标签:hdu4497 gcd and lcm 容斥原理 数论 acm
2 6 72 7 33
72 0
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> #include<set> #include<queue> #include<stack> #include<vector> #include<map> #define N 100010 #define Mod 10000007 #define lson l,mid,idx<<1 #define rson mid+1,r,idx<<1|1 #define lc idx<<1 #define rc idx<<1|1 const double EPS = 1e-11; const double PI = acos(-1.0); const double E=2.718281828; typedef long long ll; const int INF=1000010; using namespace std; map<int,int>mp; void Fenjie(int n,int d) { for(int i=2; i*i<=n; i++) { if(n%i==0) { while(n%i==0) { mp[i]+=d; n/=i; } } if(n==1) break; } if(n>1) mp[n]+=d; } int main() { //freopen("in.txt","r",stdin); int n; while(cin>>n) { while(n--) { mp.clear(); int g,l; cin>>g>>l; if(g>l||l%g) { printf("0\n"); continue; } Fenjie(l,1); Fenjie(g,-1); ll ans=1; map<int,int>::iterator it; for(it=mp.begin();it!=mp.end();it++) { if(it->second) { int x=it->second; //ans*=((x+1)*(x+1)*(x+1)-2*x*x*x+(x-1)*(x-1)*(x-1));//容斥原理 ans*=6*x;//组合原理,c(3,1)*c(2,1)*(x-1+1) } } cout<<ans<<endl; } } return 0; }
hdu 4497 GCD and LCM(唯一分解+容斥原理)
标签:hdu4497 gcd and lcm 容斥原理 数论 acm
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/40682797