poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸。注意用long long。
就是用到了两个定理
burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数
polya: 一个置换的不动置换方案数=k^(这个置换的循环个数)
先看第一个博客再看第二个
http://endlesscount.blog.163.com/blog/static/82119787201221324524202/
这两个蛮好的,上代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; int n; long long mi(int a)
{
long long ans = , zan = ;
while (a)
{
if (a & ) ans *= zan;
zan *= zan;
a >>= ;
}
return ans;
} int gcd(int a, int b)
{
if (!b) return a;
return gcd(b, a%b);
} int main()
{
scanf("%d", &n);
while (n != -)
{
if (n == )
{
printf("0\n");
scanf("%d", &n);
continue;
}
int Gcount = *n;
long long ans = ;
for (int i = ; i <= n; ++i)
ans += mi(gcd(i,n));
if (n % == ) ans += mi(n/)*n/ + mi(n/+)*n/;
else ans += mi(n/+)*n;
printf("%I64d\n", ans / Gcount);
scanf("%d", &n);
}
return ;
}
poj 1286 Necklace of Beads的更多相关文章
- 数学计数原理(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(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- 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的第一道题,在楠神的带领下,理解的还算挺 ...
- 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(旋转+翻转)+模板)
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++ BackColor_Dialog
相关主题 1. 用纯色 设置对话对话框的背景色 2. 用位图 设置对话对话框的背景色 3. 使用Picture Ctrl来设置背景图片 对话框背景色 其他相关 CColorDi ...
- 【读jQuery源码有感系列一】callee
<script type="text/javascript"> /*调用自身*/ function calleeDemo() { try{ } catch (error ...
- sql优化-隐形转换危害
level 整形字段 a:select * form t_user where level =2; b:select * form t_user where level ='2'; b里面的隐形字段 ...
- MySQL 灵异事件一则 -- desc报语法错误
今天有一开发同学找到我,说查询SQL中倒序报错,不明原因,于是奔赴工位现场研究情况. 果然,只要SQL中带有desc 就会报错,而ASC没问题. 哪怕desc放在句首用作explain也会报错. 报错 ...
- UNIX基础知识之程序和进程
一.程序 程序(program)是存放在磁盘上.处于某个目录中的一个可执行文件.使用6个exec函数中的一个由内核将程序读入存储器,并使其执行. 二.进程和进程ID 程序的执行实例被称为进程(proc ...
- 判断脚本,图片,CSS,iframe等是否加载完成
1.图片 <img id="MyImg" src="src"/>jquery实现:$("#MyImg").load(functi ...
- Windows Service 之 安装失败后的删除
一个windows服务在卸载之后并不会马上从服务列表中消失掉,而是在服务列表中会显示服务被禁用:这样在你需要再次安装同名服务时,就装不了了,会被提示同名的服务已经存在.如果是在本地安装,这种情况很容易 ...
- Pretty Poem
Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are man ...
- lisener在web.xml中设置
/* * servlet监听器开发步骤: * 1.写一个类实现XXXListener接口(6个=3个容器+3个对容器中属性进行操作) * 2.在web.xml中配置<listener> - ...
- poj1753解题报告(枚举、组合数)
POJ 1753,题目链接http://poj.org/problem?id=1753 题意: 有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白-> ...