经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C » 查看文章
洛谷P1072 Hankson 的趣味题(数学)
来源:cnblogs  作者:自为风月马前卒  时间:2018/10/29 10:00:22  对本文有异议

题意

题目链接

Sol

充满套路的数学题。。

如果你学过莫比乌斯反演的话不难得到两个等式

\[gcd(\frac{x}{a_1}, \frac{a_0}{a_1}) = 1\]

\[gcd(\frac{b_1}{b_0}, \frac{b_1}{x}) = 1\]

然后枚举\(b_1\)的约数就做完了。。

  1. // luogu-judger-enable-o2
  2. // luogu-judger-enable-o2
  3. #include<bits/stdc++.h>
  4. #define LL long long
  5. using namespace std;
  6. const int MAXN = 1e6;
  7. inline int read() {
  8. char c = getchar(); int x = 0, f = 1;
  9. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  10. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  11. return x * f;
  12. }
  13. int T, a0, a1, b0, b1, ans;
  14. int gcd(int a, int b) {
  15. return b == 0 ? a : gcd(b, a % b);
  16. }
  17. void check(int x) {
  18. if(x % a1) return ;
  19. ans += (gcd(x / a1, a0 / a1) == 1 && gcd(b1 / b0, b1 / x) == 1);
  20. }
  21. int main() {
  22. T = read();
  23. while(T--) {
  24. a0 = read(), a1 = read(), b0 = read(), b1 = read(); ans = 0;
  25. for(int x = 1; x * x <= b1; x++) {
  26. if(b1 % x == 0) {
  27. check(x);
  28. if(b1 != x) check(b1 / x);
  29. }
  30. }
  31. cout << ans << endl;
  32. }
  33. return 0;
  34. }
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号