Necklace of Beads
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7874   Accepted: 3290

Description

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 <cstdio>
#include <iostream>
using namespace std;
long long aaaa(long long a,long long b)
{
long long res=,tmp=a;
while(b)
{
if (b&)
res*=tmp;
tmp*=tmp;
b>>=;
}
return res;
}
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int n;
while ( ~scanf("%d", &n) && n != -)
{
long long a = , b = ;
for (int i=;i<n;i++)
{
a+=aaaa(,gcd(i,n));
}
if (n&)
b=(long long)n*aaaa(,(n+)/);
else
b=(long long)n/*(aaaa(,n/+)+aaaa(,n/));
if (n==)
printf("0\n");
else
printf("%lld\n",(a+b)//n);
}
return ;
}

POJ 1286 Necklace of Beads(项链的珠子)的更多相关文章

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

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

  2. POJ 1286 Necklace of Beads(Polya简单应用)

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  3. 数学计数原理(Pólya):POJ 1286 Necklace of Beads

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

  4. poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>

    链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...

  5. POJ 1286 Necklace of Beads(Polya原理)

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

  6. poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)

    题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...

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

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

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

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

  9. poj 1286 Necklace of Beads【polya定理+burnside引理】

    和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...

随机推荐

  1. mysql中取系统当前时间

    <select id="getFreightEfclInventoryList" parameterType="long" resultMap=" ...

  2. var foo= {} ;foo.method() 和 单例模式有什么区别

    var Foo={} Foo.method = function() { var i = 0; return { a:function(){ console.log('aa', i++); }, b: ...

  3. iTween_ValueTo函数

    ValueTo:返回一个插值在两件值之间的值供回调函数使用; 网上没找到例子,自己试了下,直接看代码就明白了. , 0, 0),// gameObject.transform.position为0.0 ...

  4. chord原理的解读

    chord: A Scalable Peer-to-peer Lookup Service for Internet Application 在 P2P 系统中,有效地定位分布在网络中不同节点的数据资 ...

  5. LeetCode_Scramble String

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  6. Win8/8.1/10获得完整管理员权限的方法

    WIN+R,运行对话框中输入gpedit.msc,开启组策略,然后一步步地在“计算机配置”-“Windows 设置”-“安全设置”-“本地策略”-“安全选项”,找到右侧的“用户账户控制:以管理员批准模 ...

  7. Js树型控件Dtree使用

    dtree地址:http://destroydrop.com/javascripts/tree/ Key features Unlimited number of levels 无限级 Can be ...

  8. BOT、BT、PPP形式介绍(2)

    BT1.什么是BT     BT投资是BOT的一种变换形式,即Build-Transfer(建设—转让),政府通过特许协议,引入国外资金或民间资金进行专属于政府的基础设施建设,基础设施建设完工后,该项 ...

  9. bzoj 1189

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1189 这道题目看起来好像要用很高端的网络流. 这道题有一个特别之处,就是每一个空地都有人,不是 ...

  10. 华为u8800怎样root?

    用SuperOneClick就可以root了 .在手机上面进入设置-应用程序-开发-三个都要勾选.用数据线连接到电脑,确认可正常连接.不行就使用豌豆夹连接,豌豆夹会自动帮你安装手机的驱动.运行Supe ...