hdu 1817 Necklace of Beads (polya)
Necklace of Beads
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1049 Accepted Submission(s): 378
-1 denotes the end of the input file.
4
5
-1
21
39
C/C++:
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAX = 1e5 + ; __int64 sum, n; __int64 gcd(__int64 a, __int64 b)
{
if (b == ) return a;
return gcd(b, a%b);
} __int64 my_pow(__int64 a, __int64 m)
{
__int64 ans = ;
while (m)
{
if (m & ) ans *= a;
a *= a;
m >>= ;
}
return ans;
} int main()
{
while (scanf("%I64d", &n), n != -)
{
sum = ;
if (n <= )
{
printf("0\n");
continue;
}
for (__int64 i = ; i <= n; ++ i)
{
__int64 temp = gcd(i, n);
sum += my_pow(, temp);
}
if (n & )
sum += n * my_pow(, (n + ) >> );
else
{
sum += (n >> ) * my_pow(, (n + ) >> );
sum += (n >> ) * my_pow(, n >> );
}
printf("%I64d\n", sum / / n);
}
return ;
}
hdu 1817 Necklace of Beads (polya)的更多相关文章
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...
- Necklace of Beads(polya定理)
http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...
- POJ 1286 Necklace of Beads(Polya简单应用)
Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...
- POJ 1286 Necklace of Beads(项链的珠子)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7874 Accepted: 3290 ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
随机推荐
- IDA快捷键整理
空格键 反汇编窗口切换文本跟图形 ESC退到上一个操作地址 G搜索地址或者符号 N重命名 分号键 注释 ALT+M 添加标签 CTRL+M 列出所有标签 CTRL +S 二进制段的开始地址结束地址 C ...
- [Luogu3787] 冰精冻西瓜
题目背景 盛夏,冰之妖精琪露诺发现了一大片西瓜地,终于可以吃到美味的冻西瓜啦. 题目描述 琪露诺是拥有操纵冷气程度的能力的妖精,一天她发现了一片西瓜地.这里有n个西瓜,由n-1条西瓜蔓连接,形成一个有 ...
- [BZOJ4947] 字符串大师 - KMP
4974: [Lydsy1708月赛]字符串大师 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 739 Solved: 358[Submit][Sta ...
- gedit 外部工具——快捷运行
可快捷编译运行一些代码,适合新手使用. 配置如下. 快捷键:F5 保存:当前文档 输入:无 输出:无 使用范围:所有文档,所有语言 脚本如下. #!/bin/sh #author: srczhang# ...
- python 可变数量参数 ( 多参数返回求 参数个数,最大值,最大值)
一. 自定义一串数字求 参数个数,最大值,最大值()---------方法一: def max(*a): m=a[0] p=a[0] n=0 for x in a: if x>m: m=x n+ ...
- ggstatsplot绘图|统计+可视化,学术科研神器
本文首发于“生信补给站”公众号,https://mp.weixin.qq.com/s/zdSit97SOEpbnR18ARzixw 更多关于R语言,ggplot2绘图,生信分析的内容,敬请关注小号. ...
- 禁止浏览器缓存- make sure web page is not cached
如何禁止浏览器缓存,网上搜到的解决方法都测试无效. 基本上全都是 Cache-Control: no-cache Pragma: no-cache Expires: 0 Google了一下,找到了解决 ...
- Flutter学习笔记--Dart基础
前言 Flutter使用Dart语言开发, Dart是面向对象编程语言, 由Google2011年推出, 目前最新版本是2.4.0. 工欲善其事,必先利其器. 为了更好的开发Flutter应用, 我们 ...
- 心脏滴血漏洞复现(CVE-2014-0160)
心脏滴血漏洞简述 2014年4月7日,OpenSSL发布安全公告,在OpenSSL1.0.1版本至OpenSSL1.0.1f Beta1版本中存在漏洞,该漏洞中文名称为心脏滴血,英文名称为HeartB ...
- 学习笔记69_Logistic回归
Logistic回归(逻辑回归)进行分类的主要思想:根据现有数据对分类边界线建立回归公式,以此进行分类. 知乎上的简述: 该算法可根据已知的一系列因变量估计离散数值(比方说二进制数值 0 或 1 ,是 ...