POJ 1286 Necklace of Beads(项链的珠子)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 7874 | Accepted: 3290 |
Description

Input
-1 denotes the end of the input file.
Output
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(项链的珠子)的更多相关文章
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- 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 ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- 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. ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
随机推荐
- C++程序设计的技巧-Pimple的使用
1.Pimpl概念 在进行项目开发中可能遇到的问题,程序编译耗时很长,每一次简单修改接口之后项目都会被完全重新编译,浪费了很多时间.这个机制是Private Implementation的缩写,顾明思 ...
- html Table实现表头固定
最近一直在搞前台琐碎的东西,也学习了一下linux,没有时间对新的东西进行深入的研究和学习,没有写博客,不过归咎其原因还是在于自己的惰怠. 废话不多说,今天想将一个前台页面设计的一个小东西分享一下,那 ...
- php基础之二 函数
一.语句:分支语句,循环语句 1.分支语句: 1.1 if $a = 7;if($a == 5){ echo "相等";}else{ echo "不相等";} ...
- 编写自己的javascript功能库之Ajax(仿jquery方式)
本人学习的是php,所以就用php跟js来演示代码了,主要是锻炼自己写js的能力,练练手而已. 下面这是我编写的操作ajax的代码功能,勉强让我称之为库吧.. js代码实例(tool.ajax.js) ...
- DEDE首页调用{dede:field.content/}
过滤DEDE后台自己添加的Class文件和HTML代码: {dede:sql sql='Select content from #@__arctype where id=1'} [field:cont ...
- C语言 创建一个 txt 文件 bin输入字符 保存文件在工作文件夹里
int main(void) { char s[70]; FILE *fp; fp=fopen("123.txt","r"); if((fp=fopen(&qu ...
- java中把字节数组转换为16进制字符串
把字符串数组转换为16进制字符串 import java.security.MessageDigest; public class StringUtil { public StringUtil() { ...
- 游览器对js加载的次序
直接看例子 <body> <script> console.log("first"); var script = document.createElemen ...
- ImageMagick提取图像原始数据(ImageData/RawData)
我用的是ImageMagickWand的接口,因为这接口比Core接口更上层,所以官方文档推荐用. 抽取整个图像文件字节数据: http://www.imagemagick.org/discourse ...
- ORTP库API使用入门
一.简介 ORTP是一个支持RTP以及RFC3550协议的库,有如下的特性: (1)使用C语言编写,可以工作于windows, Linux, 以及 Unix平台 (2)实现了RFC3550协议,提供简 ...