POJ1286 Necklace of Beads
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8263 | Accepted: 3452 |
Description

Input
-1 denotes the end of the input file.
Output
Sample Input
- 4
- 5
- -1
Sample Output
- 21
- 39
Source
数学问题 统计 polya原理
和POJ2409一样的套路
- /*by SilverN*/
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<cmath>
- #include<vector>
- #define LL long long
- using namespace std;
- int read(){
- int x=,f=;char ch=getchar();
- while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- LL phi(int x){
- int m=sqrt(x+0.5);
- LL res=x;
- for(int i=;i<=m;i++)
- if(x%i==){
- res=res/i*(i-);
- while(x%i==)x/=i;
- }
- if(x>)res=res/x*(x-);
- return res;
- }
- int n;
- int gcd(int a,int b){
- return (!b)?a:gcd(b,a%b);
- }
- LL ksm(LL c,LL k){
- LL res=;
- while(k){
- if(k&)res=res*c;
- c*=c;
- k>>=;
- }
- return res;
- }
- int main(){
- int i,j;
- while(){
- n=read();
- if(n==-)break;
- if(!n){
- cout<<<<endl;
- continue;
- }
- LL ans=;
- for(i=;i<=n;i++){
- if(n%i==)ans+=ksm(,i)*phi(n/i);
- }
- if(!(n&)){
- ans+=ksm(,n/)*n/;
- ans+=ksm(,n/+)*n/;
- }
- else ans+=ksm(,(n+)/)*n;
- ans/=*n;
- cout<<ans<<endl;
- }
- return ;
- }
POJ1286 Necklace of Beads的更多相关文章
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- 【数论】【Polya定理】poj1286 Necklace of Beads
Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...
- poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...
- poj1286 Necklace of Beads【裸polya】
非常裸的polya,只是我看polya看了非常久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <ios ...
- 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(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- ubuntu设置ssh登陆
转: 默认请况下,ubuntu是不允许远程登陆的.(因为服务没有开,可以这么理解.) 想要用ssh登陆的话,要在需要登陆的系统上启动服务.即,安装ssh的服务器端 $ sudo apt-get ins ...
- C#窗口抖动
用过QQ的窗口抖动功能吧.是不是觉得很神奇?很有意思?其实,仔细想想,使用的原理还是挺简单的:让窗口的位置不断快速地发生变化. 说出了原理,是不是一下恍然大悟?顿时理解了.我以前也想过如何实现这个功能 ...
- 第三十四篇 Python面向对象之 反射(自省)
什么是反射? 反射的概念是由Smith在1982年提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它首先被程序语 ...
- Android Spiner实现Key-Value
原网址:http://www.eoeandroid.com/thread-29687-1-1.html?_dsign=02d5cd6a 学习到的方法,直接上代码了: 1.定义一个class publi ...
- Gym101981I Magic Potion(最大流)
Problem I. Magic Potion There are n heroes and m monsters living in an island. The monsters became v ...
- 1066 Root of AVL Tree (25 分)(平衡二叉树)
就是AVL的模板题了 注意细节 #include<bits/stdc++.h> using namespace std; typedef struct node; typedef node ...
- UVA 1085 House of Cards(对抗搜索)
Description Axel and Birgit like to play a card game in which they build a house of cards, gaining ...
- ubuntu 和 centOS 的apache设置
更改ubuntu的网站访问根目录: 在sudo gedit /etc/apache2/sites-enabled/000-default,把 DocumentRoot /var/www #这 ...
- Bitcoin-NG
Bitcoin-NG,一个新的可扩展的区块链协议 Bitcoin-NG仅受限于网络的传输延时,它的带宽仅受限于个人节点的处理能力.通过将比特币的区块链操作分解为两部分来实现这个性能改善:首领选择(le ...
- MapReduce 并行编程理论基础
对于mapreduce这一并行计算模型,一直以来都不是很清楚其具体的执行细节,今天看了学院一位老师的实验指导书,对这一过程有了一个初步的理解,特别是map阶段和reduce阶段,所以做了一份笔记,现在 ...