洛谷1072 Hankson 的趣味题
来源:互联网 发布:苹果主屏有什么软件 编辑:程序博客网 时间:2024/05/17 02:30
https://www.luogu.org/problem/show?pid=1072 Hankson 的趣味题
正解:素数筛+因数分解+乘法原理。简单地来说就是我不会!
但是考虑:
1.从b1入手,如果枚举x只需枚举到sqrt(b1),大的部分直接用b1/x即可。
2.考虑求gcd是log级别的,一个数的约数个数也是log级别的,所以枚举+判断的复杂度大概
3.洛谷之前的王牌评测姬“香港记者号”虽退役,但还继承其跑得快精神。
综合以上三点。。。
什么叫暴力出奇迹?这就是。
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;int a0, a1, b0, b1;int gcd (int a, int b) {return (!b)? a: gcd (b, a%b);}bool jd (int x) { if (x%a1) return 0; if (gcd (x/a1, a0/a1) != 1) return 0; if ((LL)gcd (x, b0)*b1 != (LL)x*b0) return 0; return 1;}int main () { int t; scanf ("%d", &t); while (t--) { scanf ("%d%d%d%d", &a0, &a1, &b0, &b1); int ans = 0, stb = sqrt (b1); for (int x = 1; x <= stb; ++ x) { if (b1%x) continue; if (jd (x)) ++ ans; if (b1/x != x && jd (b1/x)) ++ ans; } printf ("%d\n", ans); } return 0;}
阅读全文
0 0
- 【NOIP2009】洛谷1072 Hankson的趣味题
- 洛谷1072 Hankson 的趣味题
- Hankson的趣味题
- Hankson的趣味题
- hankson的趣味题
- 洛谷1072 hankson的趣味题 数论乱搞 非标准解法
- 洛谷 P1072 Hankson 的趣味题
- 数学-洛谷P1072 Hankson 的趣味题
- 洛谷 P1072 Hankson 的趣味题
- NOIP2009 Hankson的趣味题
- Codevs1172 Hankson的趣味题
- NOIP2009 Hankson 的趣味题
- NOIP2009 Hankson的趣味题
- 【noip】HankSon的趣味题
- NOIp2009 Hankson的趣味题
- 1172 Hankson 的趣味题
- 【Noip2009】hankson的趣味题
- P1072 Hankson 的趣味题
- E
- python http通信中字典,列表等数据结构unicode转utf-8的转码问题
- 1125
- 最小割+强连通分量 COGS 426 血帆海盗
- 2017暑期ACM俱乐部个人训练赛第5场 J题
- 洛谷1072 Hankson 的趣味题
- rc.local文件
- java中的JSON操作
- 【NYOJ-106】 背包问题
- 【牛腩】CSS
- JVM内存模型
- (3)自定义服务器,用户提交数据两种方式get,post区别
- CSU
- 杭电acm—1070 Milk