fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bitset<1000001> bs;
  5. vector<long long> primes;
  6. long long gcd(long long a, long long b) {
  7. if (a < b) return gcd(b, a);
  8. if (b == 0) return a;
  9. return gcd(b, a % b);
  10. }
  11. void sieve()
  12. {
  13. bs.set();
  14. bs[0] = bs[1] = 0;
  15. for(int p=2; p*p<=1000000; p++)
  16. {
  17. if(bs[p])
  18. {
  19. for(int i=p*p; i<=1000000; i+=p)
  20. bs[i] = 0;
  21. }
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. cin.tie(0);
  28. cin.sync_with_stdio(0);
  29.  
  30. long long a,b,ans=1;
  31. cin >> a >> b;
  32. a = gcd(a,b);
  33. sieve();
  34. for(long long j=2;j<=1000000;j++){
  35. if(bs[j]) primes.push_back(j);
  36. }
  37. for(long long i:primes)
  38. {
  39. if (a%i == 0) ans++;
  40. while(a%i==0)
  41. a /= i;
  42. }
  43. if(a!=1) ans++;
  44.  
  45. cout << ans;
  46. return 0;
  47. }
  48.  
  49.  
  50.  
  51.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
4