利用bzoj2705的结论我们很容易优化这道等价类计数的问题 sum(n^gcd(i,n))/n mod p (1<=i<=n) =sum(phi(n/L)*n^L)/n mod p (n mod L=0) =sum(phi(n/L)*n^(L-1)) mod p 这题时限略紧,我的pascal怎么都卡不过去,请指教 ..] of longint; s,p,i,t,m:longint; n,ans:longint; function quick(x:longint):longi…
你随便写一下出来,发现polya原理的式子里面好多gcd是相同的,gcd(n,i)=k可以改写成gcd(n/k,i/k)=1,也就是说指数为k的项的个数为phi(n/k),就很好求了,最后除的那个n直接放到指数上即可,没必要用逆元. import java.util.*; import java.io.*; public class Main { public static int phi(int n){ int ans=n; for(int i=2;i*i<=n;++i){ if(n%i==0…
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10322 Accepted: 3360 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of the nec…
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11654 Accepted: 3756 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of the nec…