标签:des style blog http color os io strong
Time Limit: 3000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
Sample Output
Hint
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
Source
#include<iostream> using namespace std; #define max 100005 long long uler[max]; int num[max]; int p[max][30]; void init() { uler[1]=1; for(int i=2;i<max;i++) { if(!uler[i]) { for(int j=i;j<max;j+=i) { if(!uler[j]) uler[j]=j; uler[j]=uler[j]*(i-1)/i; p[j][num[j]++]=i; } } uler[i]+=uler[i-1]; } } int dfs(int k,int b,int now) { int ans=0; for(int i=k;i<num[now];i++) ans+=b/p[now][i]-dfs(i+1,b/p[now][i],now); return ans; } int main() { int cas,cas1=1; init(); cin>>cas; while(cas--) { int a,b,c,d,k; scanf("%d%d%d%d%d",&a,&b,&c,&d,&k); if(k==0) {cout<<"Case "<<cas1++<<": "<<0<<endl;continue;} if(b>d) swap(b,d); int m=b/k,n=d/k; long long ans=0; ans+=uler[m]; for(int i=m+1;i<=n;i++) ans+=m-dfs(0,m,i); cout<<"Case "<<cas1++<<": "<<ans<<endl; } return 0; }
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/khbcsu/p/3911733.html