4423:necklacedescription
Baihacker bought a necklace for he wife on their wedding anniversary. A necklace with n pearls can being treated as a circle with N points where thedistance between any and adjacent points is the Same. His wife wants to Colorevery point, but there is at the most 2 kinds of color. How many different waysto color the necklace. Ways is said to being the same IFF we rotate oneand obtain the other.
Input
The first line was an integer T, stands for the number of test cases. Then T-line follow and all line are a test case consisted of an integer n.constraints:t are in the range of [0, 4000]n is I n the range of [1, 1000000000]n is in the range of [1, 1000000], for at least 75% cases.
Output
For each case output of the answer modulo 1000000007 in a single line.
Sample Input
61234520
Sample Output
2346852488
Author
Baihacker
Crazy template problems, can not stand, the game even this theorem has not heard, but also foolishly thought for a long time, dizzy dead-
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>using namespacestd;#definell Long Long#defineN 32000ll Tot;ll prime[n+Ten];BOOLisprime[n+Ten];ll phi[n+Ten];voidinit () {memset (phi,-1,sizeof(PHI)); memset (IsPrime,1,sizeof(IsPrime)); Tot=0; phi[1]=1; isprime[0]=isprime[1]=0; for(LL i=2; i<=n;i++) { if(Isprime[i]) {Prime[tot++]=i; Phi[i]=i-1; } for(LL j=0; j<tot;j++) { if(i*prime[j]>n) Break; Isprime[i*prime[j]]=0; if(i%prime[j]==0) {Phi[i*prime[j]]=phi[i]*Prime[j]; Break; } ElsePhi[i*prime[j]]=phi[i]* (prime[j]-1); }}}ll Euler (ll N) {if(n<=n)returnPhi[n]; LL ret=N; for(LL i=0;p rime[i]*prime[i]<=n;i++) { if(n%prime[i]==0) {ret-=ret/Prime[i]; while(n%prime[i]==0) n/=Prime[i]; } } if(n>1) ret-=ret/N; returnret;} ll Quickpow (ll a,ll b,ll MOD) {a%=MOD; LL ret=1; while(b) {if(b&1) ret= (ret*a)%MOD; A= (a*a)%MOD; b>>=1; } returnret;} ll EXGCD (ll A,ll b,ll& X, ll&y) { if(b==0) {x=1; Y=0; returnA; } ll D=EXGCD (b,a%b,y,x); Y-=a/b*x; returnD;} LL INV (ll A,ll MOD) {ll x, y; EXGCD (A,mod,x,y); X= (x%mod+mod)%MOD; returnx;}voidSolve (ll n,ll MOD) {ll I,t1,t2,ans=0; for(i=1; i*i<=n;i++) { if(n%i==0) { if(i*i!=N) {T1=euler (n/i)%mod*quickpow (2, I,mod); T2=euler (i)%mod*quickpow (2, n/i,mod); Ans= (ans+t1+t2)%MOD; } Elseans= (Ans+euler (i) *quickpow (2, I,mod))%MOD; }} ans=ANS*INV (n,mod)%MOD; printf ("%d\n", ans);}intMain () {init (); ll T,n; ll MOD=1000000007; scanf ("%lld",&T); while(t--) {scanf ("%lld",&N); Solve (N,MOD); } return 0;}
[Scu 4423] Necklace