Let it Bead

大意:给你m种颜色,n个珠子串起来。旋转跟反转同样算同样,问有多少种不同的涂色组合方式。

思路:Polya的简单应用。

/*************************************************************************
> File Name: POJ2409.cpp
> Author: GLSilence
> Created Time: 2014年07月29日 星期二 22时56分58秒
************************************************************************/ #include<stdio.h>
#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;
} int n, m; int main()
{
while(~scanf("%d%d", &m, &n) && (n||m)){
LL ans = 0; for(int i = 1; i <= n; ++i){
ans += (LL)pow(m*1.0, GCD(n, i));
} if(n%2){
ans += n*(LL)pow(m*1.0, n/2+1);
}
else {
ans += n/2*(LL)pow(m*1.0, n/2);
ans += n/2*(LL)pow(m*1.0, n/2+1);
} printf("%lld\n", ans/2/n); } return 0;
}

POJ 2409 Let it Bead(Polya简单应用)的更多相关文章

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

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

  2. poj 2409 Let it Bead Polya计数

    旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文 ...

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

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

  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. (判断url文件大小)关于inputStream.available()方法获取下载文件的总大小

    转自:http://hold-on.iteye.com/blog/1017449 如果用inputStream对象的available()方法获取流中可读取的数据大小,通常我们调用这个函数是在下载文件 ...

  2. c# 冒号:C#中两个冒号(::)的作用

    global::System.Console.WriteLine(number); 冒号在什么地方用. 点是空间下类,表示下一层的意思? 这里面::前面是GAC的标示符global,用法比较特殊,和. ...

  3. Xilinx Spartan6常用资源Verilog例化

    // DSP48A1 : In order to incorporate this function into the design, // Verilog : the following insta ...

  4. struts2安全漏洞

    1 背景 Struts2是apache项目下的一个web 框架,普遍应用于阿里巴巴.京东等互联网.政府.企业门户网站. 2 内容 在2013年6月底发布的Struts 2.3.15版本被曝出存在重要的 ...

  5. Appium获取安卓页面toast(java版)

    toast是什么?安卓页面上弹出的提示框,这种提示框出现在屏幕上大概3秒左右就会消失.用uiautomatorviewer根本定位不到. 准备环境,Appium版本需要1.6.3以上. 代码 初始化设 ...

  6. JAVA逐行读取TXT文件

    package help; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; imp ...

  7. 猫猫学iOS之UITextField右边设置图片,以及UITextField全解

    猫猫分享,必须精品 原创文章.欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 效果: 封装好的方法: 猫猫封装的一个小方法,简单共享出来,方便 ...

  8. vs2017 自定义生成规则 错误 MSB3721 命令 ”已退出,返回代码为 1。

    错误 MSB3721 命令 ”已退出,返回代码为 1. 解决办法:去掉yasm复选框,改为masm vs2017 自定义生成规则-编译汇编代码 VC++调用yasm编译汇编代码有三种方法:Custom ...

  9. 爪哇国新游记之十三----XML文件读写

    /** * XML读写示例 * @author hx * */ public class XmlReaderWriter{ /** * 读取一个XML文件,返回一个雇员链表 * @param file ...

  10. Linux 变量引用和命令替换

    1.变量引用 name=Andy echo $name 或 echo ${name} 2.命令替换 把命令的执行结果赋值给变量,使用倒引号或者$() APP_HOME=`pwd` 或 APP_HOME ...