本文主要是介绍POJ 2409 Let it bead 【裸polya】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
和1286一样,裸polya,可以在吉大模板找到,polya可能要看一会儿
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
long long gcd(long long a,long long b)
{return b==0?a:gcd(b,a%b);
}
int main()
{#ifndef ONLINE_JUDGE//freopen("/home/test/in.txt","r",stdin);//freopen("/home/test/myout.txt","w",stdout);#endiflong long res=0;long long s;long long c;while(cin>>c>>s){if(c==0&&s==0)break;if(s==0){cout<<"0\n";continue;}long long p[33];p[0]=1;for(long long i=1;i<=s;i++){p[i]=p[i-1]*c;//cout<<p[i]<<endl;}long long res=s&1?s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);for(long long k=1;k<=s;k++){res+=p[gcd(k,s)];}res/=2*s;cout<<res<<'\n';}return 0;
}
这篇关于POJ 2409 Let it bead 【裸polya】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!