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 ...
随机推荐
- [GDKOI2016]染色大战
Description
- 用深度优先搜索(DFS)解决多数图论问题
前言 本文大概是作者对图论大部分内容的分析和总结吧,\(\text{OI}\)和语文能力有限,且部分说明和推导可能有错误和不足,希望能指出. 创作本文是为了提供彼此学习交流的机会,也算是作者在忙碌的中 ...
- Spring Boot 开发微信公众号后台
Hello 各位小伙伴,松哥今天要和大家聊一个有意思的话题,就是使用 Spring Boot 开发微信公众号后台. 很多小伙伴可能注意到松哥的个人网站(http://www.javaboy.org)前 ...
- Ubuntu18.04 安装PGSQL
关系数据库管理系统是许多网站和应用程序的关键组成部分.它们提供了一种结构化的方式来存储,组织和访问信息. PostgreSQL或Postgres是一个关系数据库管理系统,提供SQL查询语言的实现.它是 ...
- 关于微信oauth登录的坑
这是实习公司里微信公众号的一个小项目,用的是ssm.问题是获取用户openid为空. 分析下步骤 首先用户点击微信公众号按钮 访问微信服务器获取code 跳转到项目url 拿code访问微信服务器,获 ...
- IIS服务器文件跨域问题(几乎可以解决大多数跨域问题)
Windows server 服务器 1:在管理工具中选择,找到IIS 2:打开IIS管理,找到网站 3:找到HTTP响应头标 4:打开HTTP响应头标 5:添加 添加:Access-Control- ...
- unity 截屏总结
转载与https://www.cnblogs.com/MissLi/p/8005342.html 1.针对指定的相机进行截屏 此中方式要添加yield return waitfortheEndofFr ...
- WebApp 滚动列表的实现
实现效果: 实现技术:overflow,flex,element::-webkit-scrollbar 实现步骤: //html:代码<div id="slider"> ...
- vue进入新页面,与原页面滚动到相同高度的解决方案
可以在vue路由新增scrollBehavior,控制跳转页面高度 import Router from 'vue-router' new Router({ scrollBehavior (to, f ...
- 【C#多线程】1.Thread类的使用及注意要点
Thread随便讲讲 因为在C#中,Thread类在我们的新业务上并不常用了(因为创建一个新线程要比直接从线程池拿线程更加耗费资源),并且在.NET4.0后新增了Task类即Async与await关键 ...