Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9765 Accepted Submission(s): 3652
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
#include<bits/stdc++.h> using namespace std; #define ll long long #define esp 0.00000000001 #define pi 4*atan(1) const int N=1e5+10,M=1e7+10,inf=1e9+10,mod=1e9+7; int mu[N], p[N], np[N], cnt, sum[N]; void init() { mu[1]=1; for(int i=2; i<N; ++i) { if(!np[i]) p[++cnt]=i, mu[i]=-1; for(int j=1; j<=cnt && i*p[j]<N; ++j) { int t=i*p[j]; np[t]=1; if(i%p[j]==0) { mu[t]=0; break; } mu[t]=-mu[i]; } } } int main() { int T,cas=1; init(); scanf("%d",&T); while(T--) { int a,b,c,d,k; scanf("%d%d%d%d%d",&a,&b,&c,&d,&k); if(k==0) { printf("Case %d: 0\n",cas++); continue; } b/=k,d/=k; if(b>=d)swap(b,d); ll ans=0; for(int i=1;i<=b;i++) { ans+=(ll)mu[i]*(b/i)*(d/i); } ll ans2=0; for(int i=1;i<=b;i++) { ans2+=(ll)mu[i]*(b/i)*(b/i); } printf("Case %d: %lld\n",cas++,ans-ans2/2); } return 0; }