rembocoder

Untitled

Apr 6th, 2023
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. const int inf = 2e18;
  8. const int mod = 1e9 + 7;
  9.  
  10. int32_t main() {
  11.     ios_base::sync_with_stdio(0);
  12.     cin.tie(0); cout.tie(0);
  13.     int n, a;
  14.     cin >> n >> a;
  15.     vector<int> p;
  16.     int a_copy = a;
  17.     for (int i = 2; i * i <= a_copy; i++) {
  18.         if (a_copy % i) {
  19.             continue;
  20.         }
  21.         p.push_back(i);
  22.         while (a_copy % i == 0) {
  23.             a_copy /= i;
  24.         }
  25.     }
  26.     if (a_copy > 1) {
  27.         p.push_back(a_copy);
  28.     }
  29.     int ans = 0;
  30.     for (int mask = 1; mask < (1 << p.size()); mask++) {
  31.         int prod = 1;
  32.         for (int i = 0; i < p.size(); i++) {
  33.             if ((mask >> i) & 1) {
  34.                 prod *= p[i];
  35.             }
  36.         }
  37.         if (__builtin_popcountll(mask) % 2) {
  38.             ans += n / prod;
  39.         } else {
  40.             ans -= n / prod;
  41.         }
  42.     }
  43.     cout << n - ans << '\n';
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment