寻找a和b的互质公因子:
a和b的公因子小于等于gcd(a,b)
然后互质等价于筛gcd内的质数(公因子是gcd的因数)
复杂度O(sqrt(n))
#include<bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define bg begin() #define ed end() #define rbg rbegin() #define all(x) x.bg,x.ed using namespace std; const long long inf=2e18; typedef long long ll; typedef pair<ll,ll>pii; typedef vector<ll>vi; const double eps=1e-8; const long double pi=acos(-1.0); const int mod=998244353; const int N=2e5+5; void solve(){ int a,b; cin>>a>>b; int tmp=__gcd(a,b); int ans=0; for(int i=2;i<=tmp/i;i++){ if(tmp%i==0){ ans++; while(tmp%i==0)tmp/=i; } } if(tmp>1)ans++; cout<<ans+1<<endl; } signed main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); //int t; //cin>>t; //while(t--){ solve(); //} return 0; }
标签:abc142,const,gcd,int,个数,long,互质,define From: https://www.cnblogs.com/Candyk8d9/p/16795455.html