poj2409 Let it Bead(polya)

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值