[关闭]
@WangYixu 2018-06-15T11:35:50.000000Z 字数 625 阅读 570

[Hdu4497]GCD and LCM

OI 题解 数论 数学

算法:数论

  1. 如果,不合法,输出零。
  2. ,分别唯一分解,对于某个质因子,其指数为,如果,那么的指数只能为,如果,那么中必有一个数的指数为,一个为,一个满足,这样的三元组一共有种。

代码

这里做了一个小改动:直接分解

本来还打了素数表,不知道为什么WA了

  1. #include<cstdio>
  2. #include<cstring>
  3. #define ll long long
  4. const int N = (1 << 20) + 10;
  5. ll l[N], g[N];
  6. ll L, G;
  7. inline void factor() {
  8. memset(g, 0, sizeof(g));
  9. memset(l, 0, sizeof(l));
  10. if (L % G) {
  11. printf("0\n");
  12. return;
  13. }
  14. ll ans = 1;
  15. L /= G;
  16. for (register int i = 2; L > 1; ++i) {
  17. int cnt = 0;
  18. while (L % i == 0 && L > 1) {
  19. L /= i;
  20. cnt++;
  21. }
  22. if (cnt) ans *= 6 * cnt;
  23. }
  24. printf("%d\n", ans);
  25. }
  26. int main() {
  27. int n;
  28. scanf("%d", &n);
  29. while (n--) {
  30. scanf("%lld %lld", &G, &L);
  31. factor();
  32. }
  33. return 0;
  34. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注