The meaning of problems
Title Description
Given a $ n-$ points, cycloalkyl $ n-$ edges, there are $ n-$ colors for each vertex coloring, and asked how many different nature of staining protocol, the answer to the $ 10 ^ 9 + 7 $ modulo
Note the different nature of this question, it is defined as: just can not pass through the same rotation with other staining protocols .
Input and output formats
Input formats:A first line of input $ t $, $ t $ expressed set of data
The second line, a total of $ t $ lines, each n-$ $ integer, meaning the title as shown.
Output formats:Co $ t $ lines, each digit representing the results of the staining protocol number $ 10 $ ^ 7 + 9 mod
Sample input and output
Explanation
$$ n \ leq 10 ^ 9 $$ $$ t \ leq 10 ^ 3 $$
analysis
Fixed point number to go first formula. Consider cycling movement \ (i \) bit permutation, the beads cycle number. Since the mobile number to be repeated, so the maximum number must be \ (\ TEXTRM} {LCM (I, m) \) . Therefore, the number of beads which is one cycle \ (\ FRAC {\ TEXTRM} {LCM (I, m)} = {I} \ {n-FRAC} {\ GCD (I, n-)} \) . So a total of \ (\ gcd (i, n ) \) cycles. Thus a fixed point number \ (n ^ {\ gcd ( i, n)} \)
So the answer formula
\[ \frac 1n\sum_{i=0}^{n-1}n^{\gcd(i,n)} \\ =\frac 1n\sum_{d|n}\varphi(\frac nd)n^d \\ =\sum_{d|n}\varphi(d) n^{\frac nd-1} \]
I do not know about the number of pieces of first and then count the complexity of the Euler function of how much, anyway, how about a few number can not be achieved \ (O (\ sqrt {n }) \) upper bound.
Even \ (2 ^ 3 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 = 892 371 480 \) , this number is only about 1024 number less than \ (\ sqrt {892 371 480} = 29872.587433 \) .
int phi(int n){
int re=n;
for(int i=2;i*i<=n;++i)if(n%i==0){
re=re/i*(i-1);
while(n%i==0) n/=i;
}
if(n>1) re=re/n*(n-1);
return re;
}
void Polya(){
int n=read<int>(),ans=0;
for(int i=1;i*i<=n;++i)if(n%i==0){
ans=add(ans,mul(phi(i),fpow(n,n/i-1)));
if(i*i!=n) ans=add(ans,mul(phi(n/i),fpow(n,i-1)));
}
printf("%d\n",ans);
}
int main(){
// freopen("LG4980.in","r",stdin),freopen("LG4980.out","w",stdout);
for(int t=read<int>();t--;) Polya();
return 0;
}
Gem commemorative coins
Like above that question. But it has become more requirements: a total of 17 colors, each has to spend. Reserved 120 digits.
So simple inclusion and exclusion, and to achieve high precision.
https://cyaron.blog.luogu.org/solution-p2162
I really do not write to be considered to be a high-precision high-precision ...... practice it.
Do not want to inclusion and exclusion, then you can also use matrix multiplication: https://www.cnblogs.com/ccz181078/p/7122566.html?utm_source=itdadao&utm_medium=referral
CO int mod=1e9;int n; // qn+r
inter node(int x){
inter a(15);
a[0]=x%n,a[1]=x/n;
return a;
}
inter operator+(CO inter&a,CO inter&b){
inter ans(15);
ans[0]=a[0]+b[0];
if(ans[0]>=n) ++ans[1],ans[0]-=n;
for(int i=1;i<=14;++i){
ans[i]+=a[i]+b[i];
if(ans[i]>=mod){
if(i+1<=14) ++ans[i+1];
ans[i]-=mod;
}
}
return ans;
}
inter operator-(CO inter&a,CO inter&b){ // a>=b
inter ans(15);
ans[0]=a[0]-b[0];
if(ans[0]<0) --ans[1],ans[0]+=n;
for(int i=1;i<=14;++i){
ans[i]+=a[i]-b[i];
if(ans[i]<0){
if(i+1<=14) --ans[i+1];
ans[i]+=mod;
}
}
return ans;
}
inter operator*(CO inter&a,CO inter&b){
vector<int128> ans(15);
ans[0]=(int128)a[0]*b[0];
ans[1]+=ans[0]/n,ans[0]%=n;
for(int i=1;i<=14;++i){
ans[i]+=(int128)a[i]*b[0]+(int128)a[0]*b[i];
for(int j=1;j<=i;++j) ans[i]+=(int128)a[j]*b[i+1-j]*n;
if(i+1<=14) ans[i+1]+=ans[i]/mod;
ans[i]%=mod;
}
return inter(ans.begin(),ans.end());
}
inter pow(inter a,int b){
inter ans(15);ans[0]=1;
for(;b;b>>=1,a=a*a)
if(b&1) ans=ans*a;
return ans;
}
int phi(int n){
int ans=n;
for(int i=2;i*i<=n;++i)if(n%i==0){
ans=ans/i*(i-1);
while(n%i==0) n/=i;
}
if(n>1) ans=ans/n*(n-1);
return ans;
}
int C[20][20];
int main(){
read(n);
if(n<17){
for(int i=1;i<=120;++i) putchar('0');
puts("");
return 0;
}
for(int i=0;i<=17;++i){
C[i][0]=C[i][i]=1;
for(int j=1;j<i;++j) C[i][j]=C[i-1][j-1]+C[i-1][j];
}
inter ans(15);
for(int d=1;d*d<=n;++d)if(n%d==0){
inter sum(15);
for(int i=1;i<=17;i+=2) sum=sum+node(C[17][i])*pow(node(i),d);
for(int i=2;i<=17;i+=2) sum=sum-node(C[17][i])*pow(node(i),d);
sum=sum*node(phi(n/d));
ans=ans+sum;
if(n/d==d) continue;
sum=node(0);
for(int i=1;i<=17;i+=2) sum=sum+node(C[17][i])*pow(node(i),n/d);
for(int i=2;i<=17;i+=2) sum=sum-node(C[17][i])*pow(node(i),n/d);
sum=sum*node(phi(d));
ans=ans+sum;
}
printf("%03d",ans[14]%1000); // edit 1
for(int i=13;i>=1;--i) printf("%09d",ans[i]);
puts("");
return 0;
}