其他分享
首页 > 其他分享> > CF1295D Same GCDs

CF1295D Same GCDs

作者:互联网

原题链接

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
vector<ll>V;
void solve() {
    V.clear();
    ll a, m;
    scanf("%lld%lld", &a, &m);
    ll d = __gcd(a, m);
    ll n = m/d;
    ll ans  = n;
    for (ll i = 2; i * i <= n; i ++) {
        if ( n % i == 0) {
            ans = ans/i * (i-1);
            while (n % i == 0)n/=i;
        }
    }
    if (n > 1) {
        ans = ans / n * (n - 1);
    }
    cout << ans  << endl;
}
int main() {
    int t = 1;cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

标签:frac,gcd,ll,Same,solve,long,ans,CF1295D,GCDs
来源: https://www.cnblogs.com/Xiao-yan/p/14827528.html