poj 2049 Let it Bead(polya模板)
Description
"Let it Bead" company is located upstairs at Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced. A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=, i.e. their product does not exceed .
Output

For each test case output on a single line the number of unique bracelets. The figure below shows the different bracelets that can be made with colors and beads.
Sample Input
Sample Output
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long
ll pow_mod(ll a,ll i){
if(i==)
return ;
ll t=pow_mod(a,i/);
ll ans=t*t;
if(i&)
ans=ans*a;
return ans;
} vector<ll> divisor(ll n){
vector<ll> res;
for(ll i=;i*i<=n;i++){
if(n%i==){
res.push_back(i);
if(i*i!=n){
res.push_back(n/i);
}
}
}
return res;
} ll eular(ll n){
ll res=;
for(ll i=;i*i<=n;i++){
if(n%i==){
n/=i,res*=i-;
while(n%i==){
n/=i;
res*=i;
}
}
}
if(n>) res*=n-;
return res;
} ll polya(ll m,ll n){
vector<ll> divs = divisor(n);
ll res=;
for(ll i=;i<divs.size();i++){
ll euler=eular(divs[i]);
res+=euler*pow_mod(m,n/divs[i]);
}
res/=n;
return res;
} int main()
{
ll n,m;
while(scanf("%I64d%I64d",&m,&n)== && n+m!=){
ll ans=polya(m,n)*n;//旋转情况
if(n&){//奇数
ans+=n*pow_mod(m,n/+);//翻转情况
}
else{//偶数
ans += (pow_mod(m, n / + ) + pow_mod(m, n / )) * (n / );//翻转情况
}
ans/=*n;
printf("%I64d\n",ans);
}
return ;
}
暴力枚举k
#include <iostream>
using namespace std; #define LL long long int gcd(int a, int b)
{
return b == ? a : gcd(b, a % b);
} LL power(LL p, LL n)
{
LL sum = ;
while (n)
{
if (n & )
sum *= p;
p *= p;
n /= ; }
return sum;
} ///////////////////////////SubMain//////////////////////////////////
int main()
{ LL n; LL m;
while (~scanf("%I64d%I64d", &m,&n) && n+m!=)
{
LL count = ;
for (int i = ; i <= n; ++i)
count += power(m, gcd(i, n));
if (n & )
count += n * power(m, n / + );
else
count += n / * (power(m, n / + ) + power(m, n / ));
count /= n * ;
printf("%lld\n", count);
} return ;
}
poj 2049 Let it Bead(polya模板)的更多相关文章
- POJ 2409 Let it Bead (Polya定理)
题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...
- poj 2409 Let it Bead Polya计数
旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文 ...
- [ACM] POJ 2409 Let it Bead (Polya计数)
参考:https://blog.csdn.net/sr_19930829/article/details/38108871 #include <iostream> #include < ...
- 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:/ ...
- POJ 2406 Power Strings 简单KMP模板 strcmp
http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...
- bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- POJ 2409 Let it Bead【Polya定理】(模板题)
<题目链接> 题目大意:用k种颜色对n个珠子构成的环上色,旋转.翻转后相同的只算一种,求不等价的着色方案数. 解题分析: 对于这种等价计数问题,可以用polay定理来解决,本题是一道pol ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
随机推荐
- lesson8:AtomicInteger源码解析及性能分析
AtomicInteger等对象出现的目的主要是为了解决在多线程环境下变量计数的问题,例如常用的i++,i--操作,它们不是线程安全的,AtomicInteger引入后,就不必在进行i++和i--操作 ...
- SUSE 在Intel举行"Rule The Stack"的竞赛中获得 "Openstack安装最高速"奖
有关"Rule The Stack": https://communities.intel.com/community/itpeernetwork/datastack/blog/2 ...
- 类型转换操作符static_cast、const_cast、dynamic_cast、reinterpret_cast
一.static_cast 对于类型转换,我们常常这么做: (type) expression 引进了static_cast类型转换操作符后,我们只需这样做: static_cast<type& ...
- Oracle VM VirtualBox 随系统自动启动虚拟机的方法
Oracle VM VirtualBox 随系统自动开启虚拟机的方法 @ECHO OFFcd..cd E:cd..cd E:\VirtualBox\start VirtualBox.exe -star ...
- AngularJs练习Demo14自定义服务
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- Swift 语言函数
import Foundation // 函数声明于实现 func sayHello(name){ print("Hello \(name)") } // 函数调用 sayHell ...
- 禁止chrome中CORS跨域资源共享错误
在开发中,可以通过命令行命令chrome --allow-file-access-from-files来 禁止CORS错误. 只在紧急情况下使用这个方法,比如你的老板正站在你身后, 并且所有事情都无法 ...
- Java系列--第七篇 基于Maven的Android开发实战项目
本篇是基于<Android应用案例开发大全,吴亚峰等著>的项目开发实例源码,其中有些图片,我做了一些修改,用于个人学习,请勿用于商业. 1, 日程管理专家 mvn archetype:ge ...
- Guava API学习之Multimap
相信大家对Java中的Map类及其之类有大致的了解,Map类是以键值对的形式来存储元素(Key->Value),但是熟悉Map的人都知 道,Map中存储的Key是唯一的.什么意思呢?就是假如我们 ...
- C语言的画图(圆形动画)
#include <stdio.h> #include <malloc.h>#include<graphics.h> #define LEN sizeof(stru ...