#include <iostream>
#include <math.h> using namespace std; #define LL long long
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
} LL polya(LL n)
{
LL ret = ;
for(LL i = ; i < n; i++)
ret += pow(, gcd(i, n));
//flip them...
if( n & )//odd
ret += n * pow(, n / + );//symmetric axis's num is n, and a cycle of (n + 1) / 2, with the length of 2, and 2 cycles with length of 1... else//even ret += n / 2 * pow(3, n / 2) + (n / 2) * pow(3, n / 2 + 1);//symmetric axis's num is n, categoried by the beeds, for n/2 axis which through the beed, they formed (n/2-1) cycles with the length of 2, and 2 cycles with the length of 1; for the n/2 axis which not through the beed, they formed (n/2) cycles with the length of 2.
else//even
ret += n / * pow(, n / ) + (n / ) * pow(, n / + );// return ret / n / ;//the average of them(according to Polya Theorem.)
} int main()
{
LL n;
while(cin>> n && n != -)
{
if (n <= ) cout << << endl;
else cout << polya(n) << endl;
}
return ;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath> using namespace std;
#define n 3 __int64 m; int gcd(int a, int b)
{
b = b % a;
while (b)
{
a = a % b;
swap(a, b);
}
return a;
} int main()
{
while (scanf("%lld", &m)!=EOF)
{
if(m==-)
break;
__int64 ans = ;
for (int i = ; i <= m; i++)
ans += pow(n*1.0, gcd(i, m)*1.0);
if (m & )
ans += m * pow(n*1.0, (m / + )*1.0);
else
ans += m / * pow(n*1.0, (m / )*1.0) + m / * pow(n*1.0, (m / + )*1.0);
ans /= m * ;
printf("%I64d\n", ans);
}
return ;
}

poj 1286&&poj2409 Polya计数 颜色匹配的更多相关文章

  1. POJ 1286 【POLYA】

    题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...

  2. [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7630   Accepted: 2507 Description ...

  3. poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

  4. Polya计数

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5365   Accepted: 3585 Descr ...

  5. 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 ...

  6. 《程序设计中的组合数学》——polya计数

    我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...

  7. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  8. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. 组合数学及其应用——polya计数

    在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...

随机推荐

  1. css之absolute绝对定位(技巧篇)

    无依赖的绝对定位 margin,text-align与绝对定位的巧妙用法 例子1:实现左右上角的图标覆盖,如图,

  2. brew 任何命令 都 报 synatx error

    brew 忽然不能用了,任何命令都报 syntax error near unexpected token `<<<' 解决方案 cd $(brew --prefix) git fe ...

  3. 【redis】redis 在 windows 下安装使用

    1.安装 windows 下 redis 可用客户端 : http://redisdesktop.com/download ; 或在 github 上下载 redis zip 包,解压包到某个目录并在 ...

  4. adv联系题

    http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html(新)

  5. fool

    from PIL import Imageimg = Image.open("D:\\pic2\\CZA3302.png")(w,h) = img.sizeim=img.conve ...

  6. Hibernate配置与事务管理

    数据库中 @num:代表一个变量 Set @num = 10; Select @num+@num from dual;  dual:临时表 得到结果 20 Hibernate:运用数据持久化,使用OR ...

  7. crack.vbs病毒,优盘里所有文件全变成快捷方式

    去了一趟学校打印店,用优盘copy打印了点东西,当时在打印店电脑里打开优盘的时候里面就变成了快捷方式,但没怎么在意.回来之后在自己电脑上居然也这样了.网上一搜是中了crack.vbs病毒了.格式化优盘 ...

  8. js-正则表达式的替换

    正则表达式替换使用的是replace()方法.Replace()方法是用一些字符途欢另一些字符 语法:stringObject.replace(regexp,replacement) regexp 必 ...

  9. 原生js-焦点图轮播

    首先是html实现页面结构及主程序 <!doctype html> <html> <head> <meta charset="utf-8" ...

  10. oracle exists

    公司项目中有用到exists,感觉挺有用的,拷贝一些感念的东西. “exists”和“in”的效率问题 1) select * from T1 where exists(select 1 from T ...