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 ...
随机推荐
- .net开发windows服务
最近一个月都异常的繁忙,项目进度非常的紧,回头看看自己的blog,整整一个5月都没有一篇文章,非常惭愧,现在补几篇文章,介绍一下我最近关注的技术.这篇文章将介绍Windows服务程序的开发.摘要:本文 ...
- SQL Server Management Studio的对象资源管理器的使用
1.查看 2.对象资源管理器 3.点到某个表的身上 4.出现以下图片,因为有时动态创建的触发器,刷新表下面的触发器可能不出来,所以来这里面找
- Spring 中各种通知
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 编码问题导致样式显示在IE中不正常
今天在做项目的时候,遇到样式显示不正常的问题,结果是因为用系统自带的notepad编辑器编辑文件时,编码格式被更改了.我们需要在Notepad++中,将编码格式改成Encode inUTF8 with ...
- wpf样式绑定 行为绑定 事件关联 路由事件实例
代码说明:我要实现一个这样的功能 有三个window窗口 每个窗体有一个label标签 当我修改三个label标签中任意一个字体颜色的时候 其他的label标签字体颜色也变化 首先三个窗体不用 ...
- js字符串 数字 的转换
js 字符串转化成数字 的 三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数 ...
- 隐藏和显示 ng-show ng-hide
<div ng-controller='DeathraymenueController'> <button ng-click="toggleMenue()" ...
- Bootstrap 和 LESS
Bootstrap 简介 什么是 Bootstrap? Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的 ...
- SSH config
add a file named 'config' , place in folder .ssh then you can use "ssh yourname "quickly ...
- day2练习题
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...