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

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
  
  公式是这样子的:

  p是颜色数,这里等于3,可以发现这2*n个置换形成了置换群,满足了群的封闭性。

  那么只要对于每个置换找不动点就好了…… http://www.cnblogs.com/TenderRun/p/5656038.html 循环的部分和这题类似

 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
long long pow[],phi[],n,ans;
long long Gcd(long long a,long long b){
return b?Gcd(b,a%b):a;
}
int main(){
pow[]=;
for(int i=;i<=;i++)
pow[i]=pow[i-]*;
for(int i=;i<=;i++)
for(int j=i;j>=;j--)
if(Gcd(i,j)==)phi[i]+=;
while(scanf("%lld",&n)!=EOF&&n!=-){
if(n==){printf("0\n");continue;}
for(int d=;d<=n;d++)
if(n%d==)ans+=phi[n/d]*pow[d];
if(n%)ans=(ans+n*pow[(n+)/])//n;
else ans=(ans+n/*(pow[n/+]+pow[n/]))//n;
printf("%lld\n",ans);ans=;
}
}
												

数学计数原理(Pólya):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(项链的珠子)

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

  3. 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 ...

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

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

  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(旋转+翻转)+模板)

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

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

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

  9. poj 1286 Necklace of Beads

    这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...

随机推荐

  1. svn 1.8.11 命令行提交新添加文件错误

    由于公司的svn服务器版本不兼容最新的svn 1.8.11导致 提交代码报错 ➜  images  svn ci arrowico.png -m"add images for png ico ...

  2. U3D 背景音效和事件触发音效

    首先,想要在一个游戏添加背景音乐其实很简单,就是利用一个组件 就能够实现音频的播放,不过要实现通过某一个事件,来进行声音的播放,比如跳跃啊什么的: public AudioClip jumpclips ...

  3. Win7设置承载网络 分类: 网络 2014-10-30 09:08 105人阅读 评论(0) 收藏

    Win7设置承载网络 (1)最重要的第一步,要知道自己的网卡是否支持承载网络,如果不支持就悲剧地一票否决了,支持的话才能开始以后各步骤的设置. netsh wlan show drivers (2)设 ...

  4. br与p标签区别

    首先,相同之处是br和p都是有换行的属性及意思其次,区别<br />是只需一个单独使用,而<p>和</p>是一对使用再次,br标签是小换行提行,p标签是大换行(分段 ...

  5. StarUML启动报RPC服务器不可用错误

    有很多人说启动 Remote Procedure Call (RPC) 服务即可,还是我试过了没有起作用,后来网友说,启动Print Spooler就可以了,暂时解决了问题.

  6. StudioStyle 使用 厌倦了默认的Visutal Studio样式了,到这里找一个酷的试试

    厌倦了默认的Visutal Studio样式了,到这里找一个酷的试试 http://studiostyl.es/ 去下载个自己喜欢的编码样式吧 如果你有想法 有能力 可以自己去做一个自己喜欢的  OK ...

  7. 项目中常用SQL语句总结

    1.项目中常常需要修改字段长度,但需要保留数据--增加业务受理 项目名称 字段长度alter table t_ywsl add aa varchar2(200);update t_ywsl set a ...

  8. ORACLE 数据库简单测试

    ORACLE 数据库简单测试 操作系统:Windows 7 – ORACLE:oracle database 10.2.0.4 一.目的 测试 启动监听程序.数据库  非同一个用户的情况,用户是否可以 ...

  9. 使用charles proxy for Mac来抓取手机App的网络包

    之前做Web项目的时候,经常会使用Fiddler(Windows下).Charles Proxy(Mac下)来抓包,调试一些东西:现在搞Android App开发,有时候也需要分析手机App的网络请求 ...

  10. iOS目录结构

    默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 Documents:苹果建议将程序中建立的或在程序中浏览到的文件 ...