标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4090 Accepted Submission(s): 1619
#include <cstdio> #include <vector> using namespace std; typedef long long LL; LL sieve(LL m,LL n) { vector<LL> divisor; for(LL i=2;i*i<=n;i++) { if(n%i==0) { divisor.push_back(i); while(n%i==0) n/=i; } } if(n>1) divisor.push_back(n); LL ans=0; for(LL mark=1;mark<(1<<divisor.size());mark++) { LL odd=0; LL mul=1; for(LL i=0;i<divisor.size();i++) { if(mark&(1<<i)) { mul*=divisor[i]; odd++; } } LL cnt=m/mul; if(odd&1) ans+=cnt; else ans-=cnt; } return m-ans; } LL a,b,n; int main() { int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { scanf("%lld%lld%lld",&a,&b,&n); LL res=sieve(b,n)-sieve(a-1,n); printf("Case #%d: ",cas); printf("%lld\n",res); } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5813053.html