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

Problem Description
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 40 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

 
Input
The input has several lines, and each line contains the input data n.
-1 denotes the end of the input file.

 
Output
The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input
4
5
-1
 
Sample Output
21
39

help

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)的更多相关文章

  1. hdu 1817 Necklace of Beads(Polya定理)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. Necklace of Beads(polya计数)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7451   Accepted: 3102 ...

  3. poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  4. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  5. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  6. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

  7. POJ 1286 Necklace of Beads(Polya简单应用)

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  8. POJ 1286 Necklace of Beads(项链的珠子)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7874   Accepted: 3290 ...

  9. 数学计数原理(Pólya):POJ 1286 Necklace of Beads

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

随机推荐

  1. IDA快捷键整理

    空格键 反汇编窗口切换文本跟图形 ESC退到上一个操作地址 G搜索地址或者符号 N重命名 分号键 注释 ALT+M 添加标签 CTRL+M 列出所有标签 CTRL +S 二进制段的开始地址结束地址 C ...

  2. SpringBoot之ConfigurationProperties 源码解读

    前言 ConfigurationProperties 是SpringBoot引入的一个和外部配置文件相关的注解类.它可以帮助我们更好的使用外置的配置文件属性. 源码解析 属性注入到Java类 @Tar ...

  3. unittest断言

    assertEquals(expected,actual,msg=msg)    # 判断 expected,actual是否一致,msg类似备注,可以为空

  4. python爬取旅游数据+matplotlib简单可视化

    题目如下: 共由6个函数组成: 第一个函数爬取数据并转为DataFrame: 第二个函数爬取数据后存入Excel中,对于解题来说是多余的,仅当练手以及方便核对数据: 后面四个函数分别对应题目中的四个m ...

  5. ios 11 系统CPU过高,xib中textfield使用导致出过高

    ios11 发布之后,作为开发肯定是第一时间进行了升级测试,全新的系统不免会带来这样那样的问题.项目中使用xib的小伙伴们会发现,项目的cpu使用率非常高,尤其是初始化的时候,并没有线程的操作,CPU ...

  6. c语言-----劫持原理

    1. 劫持原理介绍 (1) 通过劫持技术我们可以实现某些进程的拦截,比如禁止创建文件,禁止打开qq,禁止关机等等一系列的操作 (2) 弹窗拦截就是最常见的一种劫持技术的实现. 2. 使用的工具 (1) ...

  7. 使用FastReport报表工具生成标签打印文档

    在我们实际开发报表的时候,我们需要按一定的业务规则组织好报表的模板设计,让报表尽可能的贴近实际的需求,在之前的随笔中<使用FastReport报表工具生成报表PDF文档>介绍了FastRe ...

  8. excel函数--笔记

    1: =DATE(MID(A1,1,4),MID(A1,5,2),MID(A1,7,2)) 字符串返回日期类型 2:  WEEKDAY(serial_number,return_type) ▪ ser ...

  9. 解决logback不打印mybatis的SQL日志的问题

    工作这么多年,今天还是因为Logback的这个问题稍微卡了一下,惭愧. 问题描述: logback配置了如下信息: <appender name="sql" class=&q ...

  10. Veins(车载通信仿真框架)入门教程(二)——调用第三方库

    Veins(车载通信仿真框架)入门教程(二)——调用第三方库 在借助Veins进行自己的研究时我们经常需要实现一些比较复杂的功能,有时就需要借助第三方库的帮助. 博主的研究需要使用神经网络,但是自己编 ...