shchuko

NokNodKey

Jan 16th, 2020
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5.  
  6. size_t factorize(long long x) {
  7.     std::vector<long long> factors;
  8.  
  9.     for (long long i = 2; i <= std::sqrt((long double) x); i++) {
  10.         if (x % i == 0) {
  11.             factors.emplace_back(i);
  12.         }
  13.  
  14.         while (x % i == 0) {
  15.             x /= i;
  16.         }
  17.     }
  18.  
  19.     if (x != 1) {
  20.         factors.emplace_back(x);
  21.     }
  22.  
  23.  
  24.     return std::pow(2, factors.size()) ;
  25. }
  26.  
  27. int main() {
  28.     long long a, b;
  29.     std::cin >> a >> b;
  30.  
  31.     if (a == b) {
  32.         std::cout << 1 << '\n';
  33.         exit(EXIT_SUCCESS);
  34.     }
  35.  
  36.     if (a < b) {
  37.         std::swap(a, b);
  38.     }
  39.  
  40.     if (a % b != 0) {
  41.         std::cout << 0 << '\n';
  42.         exit(EXIT_SUCCESS);
  43.     }
  44.  
  45.     long long to_check = a / b;
  46.     auto res = factorize(to_check);
  47.  
  48.  
  49.     std::cout << res << '\n';
  50.     return 0;
  51. }
Add Comment
Please, Sign In to add comment