Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int int64_t
- const int inf = 2e18;
- const int mod = 1e9 + 7;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- int n, a;
- cin >> n >> a;
- vector<int> p;
- int a_copy = a;
- for (int i = 2; i * i <= a_copy; i++) {
- if (a_copy % i) {
- continue;
- }
- p.push_back(i);
- while (a_copy % i == 0) {
- a_copy /= i;
- }
- }
- if (a_copy > 1) {
- p.push_back(a_copy);
- }
- int ans = 0;
- for (int mask = 1; mask < (1 << p.size()); mask++) {
- int prod = 1;
- for (int i = 0; i < p.size(); i++) {
- if ((mask >> i) & 1) {
- prod *= p[i];
- }
- }
- if (__builtin_popcountll(mask) % 2) {
- ans += n / prod;
- } else {
- ans -= n / prod;
- }
- }
- cout << n - ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment