m种颜色,给n个点的环染色,旋转同构,翻转同构。类似poj1286
你问我怎么看出来翻转同构的?看…看例子!
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define N 35
inline char gc(){
static char buf[1<<16],*S,*T;
if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
return x*f;
}
int n,m,phi[N],prime[N],tot=0;
bool notprime[N];
inline void getprime(){
notprime[1]=1;phi[1]=1;
for(int i=2;i<33;++i){
if(!notprime[i]) prime[++tot]=i,phi[i]=i-1;
for(int j=1;prime[j]*i<33;++j){
notprime[prime[j]*i]=1;
if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}
phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}
}
inline ll ksm(ll x,int k){
ll res=1;for(;k;k>>=1,x*=x) if(k&1) res*=x;return res;
}
int main(){
// freopen("a.in","r",stdin);
getprime();
while(1){
m=read();n=read();if(!n&&!m) break;if(!n){puts("0");continue;}
ll ans=0;int x=1;
for(;x*x<n;++x) if(n%x==0) ans+=ksm(m,x)*phi[n/x]+ksm(m,n/x)*phi[x];
if(x*x==n) ans+=ksm(m,x)*phi[n/x];if(n&1) ans+=ksm(m,n+1>>1)*n;
else ans+=ksm(m,n/2+1)*n/2+ksm(m,n/2)*n/2;printf("%lld\n",ans/(n*2));
}return 0;
}