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. ASP.NET JSON的序列化和反序列化 之 Newtonsoft.Json

    我们用到的类库为:Newtonsoft.Json,通过VS工具中NuGet程序包可以下载. 一:对象转json-序列化 public class Student { public int ID { g ...

  2. node里如何查看浏览器信息

    'use strict'; let http = require(`http`); http.createServer((req, res) => { console.log(req.heade ...

  3. ArcMap - 分割.

    一,分割面: 1,在屏幕上新增线分割面: 使待编辑的面处于编辑状态 -> 选择待分割的面(使其处于选中状态) -> 选择编辑工具的 (Cut Polygons Tools) ->画线 ...

  4. 利用抽象、多态实现无反射的绿色环保ORM框架

    最近一直在忙新公司的基础库建设,对系统架构.开发框架及快速开发平台的设计实施都积累了一定的实践经验. 一般的中小型的软件开发公司,如果按照技术储备来衡量软件项目的技术含量的评定依据是可行的.但如果光是 ...

  5. 【转】 iOS KVO KVC

    原文: http://www.cocoachina.com/industry/20140224/7866.html Key Value Coding Key Value Coding是cocoa的一个 ...

  6. 解决ld: warning: directory not found for option警告

    去掉警告的办法如下: 1选择工程, 编译的 (targets) 2选择 Build Settings 菜单 3查找 Library Search Paths 和 Framework Search Pa ...

  7. NSArray 跟 NSMutableArray 使用 区别

    NSArray 可变数组 一.NSArray是静态数组,创建后数组内容及长度不能再修改. 实例: //用arrayWithObjects初始化一个不可变的数组对象. //初始化的值之间使用逗号分开,以 ...

  8. SpringMVC4+thymeleaf3的一个简单实例(篇四:form表单数据验证)

    关于表单数据验证有很多中方法,这里我仅介绍JSR303注解验证.JSR303仅仅是一个规范,这里我们要用到它的一个实现:hibernate-validator. 注意在spring的配置文件sprin ...

  9. CListCtrl 的应用

    CMFCListCtrl实现的功能:比较特别的就是通过CImage来扩展每行的高度 CMFCListCtrl m_lisTestResult; 1.插入列(创建表格) m_lisTestResult. ...

  10. ExtJs中动态加载机制研究(转)

    觉得写的太好了,怕弄丢了,转一下:http://extjs.org.cn/node/659 昨天我们team对于extjs的动态加载机制做了些深入研究,这里先share下controller加载的结果 ...