Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

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

4
5
-1

Sample Output

21
39 模板题, 当然是直接上板子啦;
有对Polya定理不懂的小伙伴点这里 : 传送门
#include<iostream>
#include<cmath> using namespace std;
#define ll long long ll Pow(int value,int num)
{ __int64 sum=;
for(int i=;i<=num;i++)
sum*=value;
return sum;
} int gcd(int a, int b)
{
if(b) return gcd(b, a%b);
else return a;
} ll polya(int col, int num) // col 表示颜色种类, num 表示换环的长度
{
ll sum = ;
for(int i = ; i <= num; i++)
{
sum += Pow(col, gcd(num,i));
}
if(num&) sum += num*(Pow(col, num/+));
else sum += (Pow(col, num/) + Pow(col, num/+))*(num/);
return sum//num; } int main()
{
int n;
while(cin >> n, n != -)
{
if(n == ) cout << << endl;
else
{
ll ans = polya(,n);
cout << ans << endl;
} }
return ;
}


Necklace of Beads (polya定理的引用)的更多相关文章

  1. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  2. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

  3. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  4. poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  5. Necklace of Beads(polya计数)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7451   Accepted: 3102 ...

  6. hdu 1817 Necklace of Beads (polya)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. hdu 1817 Necklace of Beads(Polya定理)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. POJ 1286 Necklace of Beads(Polya定理)

    点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...

  9. poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

随机推荐

  1. jetty在eclipse和Idea中的使用

    eclipse中的配置 下载 http://www.eclipse.org/jetty/download.html 下载保存到特定的位置,解压. 整合到eclipse中 这里通过在eclipse中安装 ...

  2. 机器学习【工具】:Numpy基础

    Numpy Numpy 是 Python 数据科学计算的核心库,提供了高性能的多维数组对象及处理数组的工具 使用方式 import numpy as np 数组 生成数组  简单生成 a = np.a ...

  3. openssh源码分析笔记

    1.客户端保活: options.client_alive_interval options.client_alive_count_max 在wait_until_can_do_something() ...

  4. linux 循环读取文件的每一行

    在Linux中有很多方法逐行读取一个文件的方法,其中最常用的就是下面的脚本里的方法,而且是效率最高,使用最多的方法.为了给大家一个直观的感受,我们将通过生成一个大的文件的方式来检验各种方法的执行效率. ...

  5. yaml语言在线可视化翻译

    yaml语言在线可视化翻译 https://editor.swagger.io/

  6. python的目录

    1.python的当前目录 d = os.path.dirname(__file__) #和文件强依赖,即使该语句被别的文件调用,d也不会改变或者d = os.getcwd() #当该语句被别的文件调 ...

  7. Kubernetes总结

    1.Kubernetes简介 在了解Kubernetes之前,我们有必要先简单了解一下传统的运维模式.在传统的项目架构中(单体or微服务),我们一般将项目打包为war或fatJar的方式进行部署. 在 ...

  8. git cherry-pick 报错 fatal: bad object

    场景:程序员A提交了一个commit到gerrit上,我们叫他为commit_id1,但是还没有review,那就是没有入库,程序员B想再本地拿到这个commitd_id1,既然这个提交没有入库,很明 ...

  9. SmartGit 过期破解 - 授权文件 Free Trial License to Non-Commercial

    亲测可用~ Windows: %APPDATA%/syntevo/SmartGit/OS X:    ~/Library/Preferences/SmartGit/Unix/Linux:  ~/.sm ...

  10. Eclipse+GitHub 提交代码错误 -“rejected - non-fast-forward”

    Eclipse Push出现rejected - non-fast-forward错误 在 Push到服务器时有时会出现 rejected - non-fast-forward 错误,这是由于远端发生 ...