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. Error loading MySQLdb module: libmysqlclient.so.18: cannot open shared object file: No such file or directory

    在hue上配置Mysql的时候,出现的错误:  发生服务器错误: Error loading MySQLdb module: libmysqlclient.so.18: cannot open sha ...

  2. Laravel框架

    curl操作: ===================================初始化$ch=curl_init() 设置请求的urlcurl_setopt($ch,CURLOPT_URL,&q ...

  3. JAXB轻松转换xml对象和java对象

    实体类如下: package com.cn.entity; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; ...

  4. 通过repcached实现memcached主从复制

    一.环境 服务器A:ubuntu server 12.04(192.168.1.111) 服务器B:ubuntu server 12.04 (47.50.13.111) 二.memcached安装 s ...

  5. vue2.0 watch

    类型:string | Function | Object vue官网解释: 一个对象,键是需要观察的表达式,值是对应回调函数.值也可以是方法名,或者包含选项的对象.Vue 实例将会在实例化时调用 $ ...

  6. Jmeter学习(三)

    Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试.(来自百度) jmeter的特点: 开源免费. ...

  7. 第二十四篇configparser(**)

    configparser模块 config:配置,parser:解析.字面意思理解configparser模块就是配置文件的解析模块. 来看一个好多软件的常见文档格式如下: [DEFAULT] # 标 ...

  8. Jmeter使用时异常问题解决

    1.执行jmeter请求时,响应数据中出现乱码异常(如图) 解决方案: 打开E:\apache-jmeter-4\bin\jmeter.properries(jmeter安装目录),查找到语句行:#s ...

  9. docker简单命令

    查看镜像 docker images 查看正在使用的容器 docker ps -a 进入容器控制台 docker exec -it 容器ID bash 启动镜像 docker run -it -d.. ...

  10. git instaweb 500 error

    在arch 系统中安装perl-cgi包. 在deiban中参考:https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A ...