旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个

翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个

偶数时有n种置换,一半是n/2+1个,一半是n/2个

啃论文,PPT,各种书好久才看懂Polya定理,近期做数学题做的严重怀疑自己的智商。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) {return a%b==0?b:gcd(b,a%b);}
ll quickpow(ll m,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*m;
n=(n>>1);
m=m*m;
}
return ans;
}
int main()
{
ll c,n;
while(~scanf("%lld%lld",&c,&n))
{
if(c+n==0) break;
ll ans=quickpow(c,n);
for(int i=1;i<n;i++) ans+=quickpow(c,gcd(n,i));
if(n&1) ans+=n*quickpow(c,n/2+1);
else ans+=(n/2*quickpow(c,n/2+1)+n/2*(quickpow(c,n/2)));
printf("%lld\n",ans/(2*n));
}
return 0;
}

poj 2409 Let it Bead Polya计数的更多相关文章

  1. [ACM] POJ 2409 Let it Bead (Polya计数)

    参考:https://blog.csdn.net/sr_19930829/article/details/38108871 #include <iostream> #include < ...

  2. POJ 2409 Let it Bead(polay计数)

    题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...

  3. POJ 2409 Let it Bead (Polya定理)

    题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...

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

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

  5. bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...

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

  7. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

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

  9. POJ 2409 Let it Bead:置换群 Polya定理

    题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...

随机推荐

  1. selenium grid 环境搭建

    一.selenium grid简介 selenium grid可以同时在不同机器上测试不同浏览器,包含一个hub和多个node.node会发送配置信息到hub,hub记录并跟踪每一个node的配置信息 ...

  2. HDU 1556.Color the ball-差分数组-备忘

    备忘. 差分数组: 区间更新查询有很多方法,线段树.树状数组等都可以.如果为离线查询,就可以考虑使用差分数组. 假设对于区间[l,r]的每个数都加1,我们用一个数组a来记录,a[l]+=1;a[r+1 ...

  3. 11.5NOIP2018提高组模拟题

    书信(letter) Description 有 n 个小朋友, 编号为 1 到 n, 他们每人写了一封信, 放到了一个信箱里, 接下来每个人从中抽取一封书信. 显然, 这样一共有 n!种拿到书信的情 ...

  4. Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. bit & byte & B & KB & Kbps & KBps & ps

    存储单位bit & byte & B & KB & Kbps & KBps & ps    (bit,位:byte,字节:区别) Bit,位 :二进制数 ...

  6. [UOJ206]Gap

    子任务$1$:直接找到最大值后从两边开始找,一步一步从左右到中间确定所有数,调用次数是$\left\lceil\dfrac n2\right\rceil$ 子任务$2$:先找到最大值$mx$和最小值$ ...

  7. Problem B: 调用函数,求1!+2!+3!+......+10!

    #include<stdio.h> double fact(int i); int main() { int i; ; ;i<=;i++) sum=sum+fact(i); prin ...

  8. wait和notify函数的规范代码模板

    // The standard idiom for calling the wait method in Java synchronized (sharedObject) { while (condi ...

  9. 使用hsdis查看jit生成的汇编代码

     http://blog.csdn.net/unei66/article/details/26477629 JVM 有 HotSpot引擎可以对热代码路径进行有效的 JIT优化,大幅度提升计算密集代码 ...

  10. Swift,下标简化方法的调用

    在类(class)当中采用subscript的方法直接用下标 class a{ func b(number:Int)->Int{ return number } subscript(number ...