POJ 1286 Necklace of Beads (Polya)

网友投稿 612 2022-08-26

POJ 1286 Necklace of Beads (Polya)

POJ 1286 Necklace of Beads (Polya)

Description

Input

The input has several lines, and each line contains the input data n.-1 denotes the end of the input file.

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input

45-1

Sample Output

2139

题意

用三种颜色的珠子连接成一个长度为N的圆形项链,项链通过旋转或者对称得到的情况算一种,问总共有多少种不同的形式。

思路

​​POJ 2409 Let it Bead (Polya)​​ 的弱化版本,具体方法请戳左边链接。

需要注意的是,当输入为 ​​0​​​ 的时候我们要进行特判,输出也为 ​​0​​ 。

AC 代码

#include#include#include#include#include#includeusing namespace std;#include#includeint gcd(int a,int b){ if(b%a==0)return a; return gcd(b%a,a);}int main(){ int n; while(cin>>n&&n!=-1) { if(n==0) { printf("0\n"); continue; } long long ans=0; for(int i=1; i<=n; i++) ans+=pow(3,gcd(i,n)); if(n&1)ans+=n*pow(3,n/2+1); else ans+=n/2*(pow(3,n/2+1)+pow(3,n/2)); cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:POJ 2442 Sequence (堆)
下一篇:POJ 2411 Mondriaan's Dream (状压dp)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~