POJ 1286
Burnside定理。
可以用Euler函数优化。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL __int64 using namespace std; LL Power(int a,int b){
LL ret=1; LL p=(LL)a;
while(b){
if(b&1) ret=ret*p;
p=p*p;
b>>=1;
}
return ret;
} LL Euler(int s){
LL ret=(LL)s;
int l=(int)sqrt(s*1.0);
for(int i=2;i<=l;i++){
if(s%i==0){
ret=ret-ret/(LL)i;
while(s%i==0)
s/=i;
}
}
if(s>1)
ret=ret-ret/s;
return ret;
} LL Burnside(int n){
LL res=0;
for(int i=1;i<=n;i++){
if(n%i==0)
res=res+Power(3,i)*Euler(n/i);
}
if(n&1){
res=res+n*Power(3,n/2+1);
}
else{
res=res+n/2*Power(3,n/2)+n/2*Power(3,n/2+1);
}
return res;
} int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==-1) break;
if(n==0) printf("0\n");
else{
LL ans=Burnside(n);
ans=ans/2/n;
printf("%I64d\n",ans);
}
}
return 0;
}
POJ 1286的更多相关文章
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- 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 ...
- 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. ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
- poj 1286&&poj2409 Polya计数 颜色匹配
#include <iostream> #include <math.h> using namespace std; #define LL long long LL gcd(L ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- POJ 1286 【POLYA】
题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...
- poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- POJ 1286 Necklaces of Beads (Burnside定理,有限制型)
题目链接:http://vjudge.net/problem/viewProblem.action?id=11117 就是利用每种等价情形算出置换节之后算组合数 #include <stdio. ...
随机推荐
- 组件的使用(三)AutoCompleteTextView的使用
AutoCompleteTextView经常使用的属性: android:completionHint 下拉列表以下的说明性文字 android:completionThreshold 弹出下来列表的 ...
- [React] Reference a node using createRef() in React 16.3
In this lesson, we look at where we came from with refs in React. Starting with the deprecated strin ...
- 【Android 应用开发】 ActionBar 样式具体解释 -- 样式 主题 简单介绍 Actionbar 的 icon logo 标题 菜单样式改动
作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...
- [ACM] FZU 1686 神龙的难题 (DLX 反复覆盖)
Problem 1686 神龙的难题 Accept: 444 Submit: 1365 Time Limit: 1000 mSec Memory Limit : 32768 KB Pro ...
- 使用从mysql中取数据
import MySQLdb conn=MySQLdb.connect(host="xx",user="xx",passwd="xx",db ...
- (转)c++ typedef 函数指针详细说明
转自:http://blog.csdn.net/future200x/article/details/5350134 一个函数在编译时被分配一个入口地址,将这个入口地址称为函数的指针,可以用一个指针变 ...
- js写发布微博文本框---2017-04-14
实现效果: 1.文本框输入内容,低端字数对应减少 2.当文本框内容超出时,会显示字数超出多少 效果图如下: 实现代码: <!DOCTYPE html><html> <he ...
- QT-helloworld-Qt设计师编写
前言:Qt设计师界面类就是C++类和ui文件的结合,它将这两个文件一起生成了,而不用再逐一添加. 目标:在对话框中显示出“helloworld”字样. 一.新建项目 1.1 选择项目模板 文件→新建文 ...
- POJ 3660 Floyd传递闭包
题意:牛有强弱,给出一些牛的强弱的胜负关系,问可以确定几头牛的排名. 思路: Floyd传递闭包 // by SiriusRen #include <bitset> #include &l ...
- Android WebView访问网站携带登录认证Cookies和动态自定义的cookies
最近项目几个页面要复用微信程序的网页.但是需要调用微网站登录接口,返回Cookies,webview访问需要的网页的时候携带. 并且还需要几个其他的动态改变的cookie,目的是根据这几个动态自定义c ...