POJ 1286 Necklace of Beads(项链的珠子)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7874 | Accepted: 3290 |
Description

Input
-1 denotes the end of the input file.
Output
Sample Input
4
5
-1
Sample Output
21
39
/*Polya原理*/
#include <cstdio>
#include <iostream>
using namespace std;
long long aaaa(long long a,long long b)
{
long long res=,tmp=a;
while(b)
{
if (b&)
res*=tmp;
tmp*=tmp;
b>>=;
}
return res;
}
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int n;
while ( ~scanf("%d", &n) && n != -)
{
long long a = , b = ;
for (int i=;i<n;i++)
{
a+=aaaa(,gcd(i,n));
}
if (n&)
b=(long long)n*aaaa(,(n+)/);
else
b=(long long)n/*(aaaa(,n/+)+aaaa(,n/));
if (n==)
printf("0\n");
else
printf("%lld\n",(a+b)//n);
}
return ;
}
POJ 1286 Necklace of Beads(项链的珠子)的更多相关文章
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- 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 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- 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定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
随机推荐
- 转载:JSONObject简介
转载网址:http://www.cnblogs.com/java-pan/archive/2012/04/07/JSONObject.html JSONObject简介 本节摘要:之前对JSON做 ...
- 前端开发攻城师绝对不可忽视的五个HTML5新特性
HTML5已经火了一段时间了,相信作为web相关开发工程师,肯定或多或少的了解和尝试过一些HTML5的特性和编程.还记得以前我们介绍过的HTML5新标签. 作为未来前端开发技术的潮流和风向标,HTML ...
- laravel实现发送qq邮件
首先修改config/mail.php 'from' => [ 'address' => 'hello@example.com', 'name' => 'Example', ], 修 ...
- Android-4
显式Intent 隐式Intent Intent过滤器相关选项 通过浏览器链接启动本地Activity
- Gradient Descent 和 Stochastic Gradient Descent(随机梯度下降法)
Gradient Descent(Batch Gradient)也就是梯度下降法是一种常用的的寻找局域最小值的方法.其主要思想就是计算当前位置的梯度,取梯度反方向并结合合适步长使其向最小值移动.通过柯 ...
- DLog 技巧
#ifdef DEBUG#ifndef DLog# define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FU ...
- jquery easyui二次开发总结(二)
1.easyui tab增加“关闭所有页”.“关闭非当前页”功能. //tab增加“关闭所有页”和“关闭非当前页”的功能 $("#tabs").tabs({ onAdd:funct ...
- controller 和 指令 通讯方法
在 angular 中我们经常会使用多个 controller 和 指令 他们拥有各自的 $scope , 这就产生了跨$scope调用的问题. 有几种常见的方法来可以使用. 方法一 : 指令 req ...
- 基于Redis的消息订阅/发布
在工业生产设计中,我们往往需要实现一个基于消息订阅的模式,用来对非定时的的消息进行监听订阅. 这种设计模式在 总线设计模式中得到体现.微软以前的WCF中实现了服务总线 ServiceBus的设计模式. ...
- 【转】Android API 中文(14) —— ViewStub
用一个XML源填充view.inflate(上下文对象,资源文件Id,父窗口组一般为null): 原文网址:http://www.cnblogs.com/over140/archive/2010/10 ...