polya定理。等价类的个数等于∑颜色数^置换的轮换个数

不可翻转的串当中。直接计算∑m^(gcd(n,i)) ,这里gcd(n,i)就是第i个置换的轮换数。

翻转的情况再分n奇偶讨论。

n次二面体都是这个套路。

 /*--------------------------------------------------------------------------------------*/

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
const LL MOD = 1e9+; LL pow_mod(LL x,LL cnt)
{
LL base = x,res = ;
while(cnt)
{
if(cnt&) {res*=base;res%=MOD;}
base *= base;base %= MOD;
cnt >>= ;
}
return res%MOD;
}
LL inv(LL x,LL m)
{
return pow_mod(x,m-);
}
LL polya(LL n,LL m)
{
LL res = ;
for(int i=;i<=n;i++)
{
res += pow_mod(m,__gcd((LL)i,n));
res %= MOD;
} if(n&) res += n*pow_mod(m,n/+);
else res += (n*pow_mod(m,n/))%MOD*inv(,MOD)%MOD + (n*pow_mod(m,n/+))%MOD*inv(,MOD)%MOD ; res %= MOD;
res *= inv(*n,MOD); return res%MOD;
} int main()
{
scanf("%d",&T);
int cas = ;
while(T--)
{
scanf("%d%d",&M,&N);
printf("Case #%d: %lld\n",++cas,polya(N,M));
}
}

最新文章

  1. sql编程(四)触发器
  2. setProgressBarIndeterminateVisibility(true);
  3. 『TCP/IP详解——卷一:协议』读书笔记——13
  4. setAlpha方法 设置透明度
  5. Linux下安装软件的一般步骤
  6. [操作系统实验lab3]实验报告
  7. QOS
  8. kvm 启动libvirtd市出现错误
  9. window.history.back()的改进方法window.history.go()
  10. C语言第六周博客作业--数据类型
  11. React-Native(六):React Native完整的demo项目
  12. 51nod1556 计算(默慈金数)
  13. leetcode每日刷题计划-简单篇day13
  14. 机器学习算法中如何选取超参数:学习速率、正则项系数、minibatch size
  15. 洛谷.2596.[ZJOI2006]书架(Splay)
  16. J - Intersection
  17. 排序-----插入排序(python版)
  18. gridview 自动序号 合计
  19. python基础之面向对象02
  20. Python学习札记(七) Basic4 条件判断

热门文章

  1. 远程连接mysql容易遇到的2个问题
  2. opencms忘记Admin用户登录密码解决方案
  3. iperf测试
  4. 【mysql】使用tpcc-mysql进行压力测试
  5. 烂泥:【解决】ubuntu使用远程NFS报错
  6. SQL2008 提示评估期已过的解决方法
  7. Hadoop 数据库 - HBase
  8. 警惕javascript变量的全局污染问题
  9. Java性能调优笔记
  10. codeforces 721B B. Passwords(贪心)