Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8263   Accepted: 3452

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

Source

数学问题 统计 polya原理

和POJ2409一样的套路

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL phi(int x){
int m=sqrt(x+0.5);
LL res=x;
for(int i=;i<=m;i++)
if(x%i==){
res=res/i*(i-);
while(x%i==)x/=i;
}
if(x>)res=res/x*(x-);
return res;
}
int n;
int gcd(int a,int b){
return (!b)?a:gcd(b,a%b);
}
LL ksm(LL c,LL k){
LL res=;
while(k){
if(k&)res=res*c;
c*=c;
k>>=;
}
return res;
}
int main(){
int i,j;
while(){
n=read();
if(n==-)break;
if(!n){
cout<<<<endl;
continue;
}
LL ans=;
for(i=;i<=n;i++){
if(n%i==)ans+=ksm(,i)*phi(n/i);
}
if(!(n&)){
ans+=ksm(,n/)*n/;
ans+=ksm(,n/+)*n/;
}
else ans+=ksm(,(n+)/)*n;
ans/=*n;
cout<<ans<<endl;
}
return ;
}

POJ1286 Necklace of Beads的更多相关文章

  1. POJ1286 Necklace of Beads(Polya定理)

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

  2. 【数论】【Polya定理】poj1286 Necklace of Beads

    Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...

  3. poj1286 Necklace of Beads—— Polya定理

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

  4. poj1286 Necklace of Beads【裸polya】

    非常裸的polya,只是我看polya看了非常久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <ios ...

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

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

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

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

  7. POJ 1286 Necklace of Beads(项链的珠子)

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

  8. Necklace of Beads(polya计数)

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

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

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

随机推荐

  1. Vue-router使用

    Vue路由:--------------------------------------------------------1 .Vue-rouer入门2 .子路由3 .路由传参4 .多路由区域操作5 ...

  2. hibernate 各历史版本下载 spring各历史版本下载

    hibernate 各历史版本下载http://sourceforge.net/projects/hibernate/files/ spring各历史版本下载http://www.springsour ...

  3. 教你用Bootstrap开发漂亮的前端界面

    Bootstrap介绍: Bootstrap 是最受欢迎的 HTML.CSS 和 JS 框架,用于开发响应式布局.移动设备优先的 WEB 项目. Bootstrap的特点: 一.预处理脚本:虽然可以直 ...

  4. Chrome也疯狂之Vimium插件

    Chrome也疯狂之安装Vimium插件 由于最近换上了Mac,深感外设的累赘,脱离了外接鼠标以及键盘之后发现操作更加的流畅了(可怜我入手不到一年的机械键盘).当然脱离鼠标用触摸板来操作浏览器有时候还 ...

  5. Git创建project

    1.登录创建新仓库 命名 2.https://gitforwindows.org/  下载git的windows客户端,输入git查看是否成功 3.创建文件夹,写内容并查看,和linux指令一样 4. ...

  6. 【Linux运维】LNMP环境配置

    安装准备: Centos7.3 MYSQL5.6 PHP5.6 NGINX1.10.3 一.安装Mysql mysql:[root@host129 src]#cd /usr/local/src/ [r ...

  7. 在阿里云上遇见更好的Oracle(三)

    鬼扯完“去IOE”,继续回来说说这个系列文章的主角Oracle. 在DB-Engine的数据库排行榜中,Oracle已经占据了多年的第一(最新排名可以点击“阅读原文”).当然因为互联网行业的兴起,My ...

  8. 参加2018之江杯全球人工智能大赛 :视频识别&问答(四)

    很遗憾没有在规定的时间点(2018-9-25 12:00:00)完成所有的功能并上传数据,只做到写了模型代码并只跑了一轮迭代,现将代码部分贴出. import keras from keras.lay ...

  9. 从微软msdn阅读事件的使用

    微软文章:如何:在 Windows 窗体应用程序中使用事件 地址:https://msdn.microsoft.com/zh-cn/library/0y0987sc.aspx 文章:C#事件的订阅与触 ...

  10. ubuntu16.04 装了一天的gitlab

    1.安装gitlab baidu安装完了[后续再自己写安装过程] 2.遇到的问题 访问gitlab http://ip 可以进入页面也能操作但是console报404无法加载js和css,这样很不方便 ...