标签:memset end des content otto script sizeof others std
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> #include<bitset> #include<time.h> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-4 #define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+10,M=1e6+10,inf=1e9+7,MOD=1e9+7; const LL INF=1e18+10,mod=1e9+7; int a[N],sum[N]; LL dp[N],num[N]; LL qpow(LL a,LL b,LL c) { LL ans=1; while(b) { if(b%2)ans=(ans*a)%c; b>>=1; a=(a*a)%mod; } return ans; } int main() { int n; int T,cas=1; scanf("%d",&T); while(T--) { memset(a,0,sizeof(a)); memset(sum,0,sizeof(sum)); scanf("%d",&n); for(int i=1;i<=n;i++) { int x; scanf("%d",&x); a[x]++; } for(int i=1;i<=100005;i++) sum[i]=sum[i-1]+a[i]; for(int i=2;i<=100000;i++)//枚举除数 { num[i]=1LL; for(int j=0;j<=100000;j+=i) { int b; if(j+i-1>100000)b=sum[100001]-sum[j-1]; else if(j==0) b=sum[j+i-1]; else b=sum[j+i-1]-sum[j-1]; int a=j/i; if(a==0&&b)num[i]=0; else if(b)num[i]=(num[i]*qpow(a,b,mod))%mod; } } for(int i=100000;i>=2;i--) { dp[i]=num[i]; for(int j=i+i;j<=100000;j+=i) dp[i]-=dp[j],dp[i]=(dp[i]%mod+mod)%mod; } LL ans=0; for(int i=2;i<=100000;i++) ans+=dp[i],ans%=mod; printf("Case #%d: %lld\n",cas++,ans); } return 0; }
标签:memset end des content otto script sizeof others std
原文地址:http://www.cnblogs.com/jhz033/p/7246028.html