Necklace of Beads
http://poj.org/problem?id=1286
// File Name: poj1286.cpp
// Author: bo_jwolf
// Created Time: 2013年10月07日 星期一 21:31:08 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> #define INT long long int using namespace std;
INT gcd( INT a, INT b){
return b == 0? a: gcd( b, a % b );
} INT c = 3, s;
INT polya(){
INT ans = 0;
for( INT i = 0; i < s; ++i ){
ans += (INT)pow( 1.0 * c, gcd( s, i ) );
}
if( s % 2 ){
ans += s * ( INT )pow( 1.0 * c, ( s / 2 + 1 ) );
}
else{
ans += s / 2 * ( INT )pow( 1.0 * c, s / 2 );
ans += s / 2 * ( INT )pow( 1.0 * c, s / 2 + 1 );
}
return ans / 2 / s;
} int main(){
INT ans;
while( scanf( "%lld", &s ) != EOF ){
if( s == -1 )
break;
if( s == 0 )
ans = 0;
else
ans = polya();
printf( "%lld\n", ans );
}
return 0;
}
Necklace of Beads的更多相关文章
- 数学计数原理(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 ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 1817 Necklace of Beads (polya)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 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 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- Necklace of Beads (polya定理的引用)
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n &l ...
- POJ1286 Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8263 Accepted: 3452 Description Beads ...
随机推荐
- 使用XLinq.XElement读取带Namespace(命名空间)的XML
简介 本文主要介绍通过XELemet去读取含有namespaces(xmlns)的XML,这也是偶然间发现这个问题的,一个群里的小伙伴突然问起这个,以此记录一下. 背景 一个XML文档可能包括来自多个 ...
- Linux 删除文件夹
inux删除目录很简单,很多人还是习惯用rmdir 1.直接rm就可以了:rm -rf 目录名字 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思
- git学习利器:《Git Pro》中文版
Git书籍有<版本控制之道git>,但是很一般.强烈推荐<Git Pro>中文版! 很多开源软件的教程也是免费开源的在线阅读的. <Git Pro>中文版在线阅读h ...
- Oracle数据库之rownum
1. 介绍 当我们在做查询时,经常会遇到如查询限定行数或分页查询的需求,MySQL中可以使用LIMIT子句完成,在MSSQL中可以使用TOP子句完成,那么在Oracle中,我们如何实现呢? Oracl ...
- Aspnet MVC 异步调用
一个简图来描述下Aspnet MVC下的异步调用 { request } / \/ -------ISS------- > work thread | \ | \ route - aysn co ...
- 如何用DOS 链接mysql
1.Ctrl+R 打开DOS窗口 2.键入 cd\ 回车进入C盘根目录 3.进入mysql bin目录下 操作mysql命令 4.输入连接数据库命令 mysql -hlocalhost -uroot ...
- Ubuntu You don't have permission to access解决方案!
最近对Linux越来越喜欢了,就直接安装了一个Ubuntu,配制好LAMP后,在做小项目时,出现了下面的问题:Ubuntu You don't have permission to access ** ...
- IIS10 设置支持wcf服务(.svc)
感谢: http://www.cnblogs.com/dudu/p/3328066.html 如果提示web.config配置重复的话,很有可能是.net framework版本的问题,把IIS中的版 ...
- 英语学习App演示
- DotNet 资源
DotNet 资源 目录 API 应用框架(Application Frameworks) 应用模板(Application Templates) 人工智能(Artificial Intelligen ...