fork download
  1. #include <chrono>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. const int MAXN = 100005;
  7.  
  8. template <int N>
  9. struct Sieve {
  10. int nod[N];
  11. constexpr Sieve() : nod() {
  12. // memset(nod, 0, sizeof nod);
  13. for(int i = 0; i < N; i++) nod[i] = 0;
  14. for (int i = 1; i < N; i++)
  15. for(int j = i; j < N; j += i)
  16. nod[j]++;
  17. }
  18. };
  19.  
  20. int fast_get_nod(int n) {
  21. static constexpr Sieve<MAXN> s;
  22. return s.nod[n];
  23. }
  24.  
  25. int main()
  26. {
  27. int T, a, b;
  28. scanf("%d", &T);
  29. while(T--)
  30. {
  31. scanf("%d%d", &a, &b);
  32. printf("%d\n", fast_get_nod[__gcd(a, b)]);
  33. }
  34. }
Success #stdin #stdout 0.01s 5516KB
stdin
3
100000 100000
12 24
74779 23833
stdout
-1157142224
-1157242212
-1157242223