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. i春秋DMZ大型靶场实验(二)提权漏洞

    拿到靶场 直接进行扫描 爆破路径 发现 phpinfo, phpmyadmin  更具phpinfo 获取跟路径  也可以通过 输入错路径爆出绝对路径 phpmyamin  弱口令登录  root,r ...

  2. excel函数--笔记

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

  3. Sublime Text 3 安装 Package Control 结果返回 275309,找不到 Install Package

    打开 Preferences->Settings , 查看 ignored-packages 数组中是否有 Package Control,如果有,删除即可.

  4. 搭建 webpack + react 框架爬坑之路

    由于工程实践需要搭一个 webpack + react 框架,本人刚开始学,就照b站上的react黑马视频做,爬过无数个坑...希望读者能引以为戒.我的是macos系统 https://www.bil ...

  5. 设计模式(十九)State模式

    在面向对象编程中,是用类表示对象的.也就是说,程序的设计者需要考虑用类来表示什么东西.类对应的东西可能存在于真实世界中,也可能不存在于真实世界中.对于后者,可能有人看到代码后会感到吃惊:这些东西居然也 ...

  6. 第一篇:版本控制git之仓库管理

    ---恢复内容开始--- 再开始这个话题之前,让我想起了一件很痛苦的事情,在我大学写毕业论文的时候,我当时的文件是这样保存的 毕业论文_初稿.doc 毕业论文_修改1.doc 毕业论文_修改2.doc ...

  7. C语言存储类别和链接

    目录 C语言存储类别和链接 存储类别 存储期 五种存储类别 C语言存储类别和链接 ​ 最近详细的复习C语言,看到存储类别的时候总感觉一些概念模糊不清,现在认真的梳理一下.C语言的优势之一能够让程序员恰 ...

  8. 如何理解swift中的delegate

    Delegation翻译为代理或者委托,是一种设计模式.顾名思义,使class或struct能够将某些职责移交给其他类型的实例. 该设计模式通过定义一个封装(包含)delegate的protocol( ...

  9. UE4蓝图与C++交互——射击游戏中多武器系统的实现

    回顾   学习UE4已有近2周的时间,跟着数天学院"UE4游戏开发"课程的学习,已经完成了UE4蓝图方面比较基础性的学习.通过UE4蓝图的开发,我实现了类似CS的单人版射击游戏,效 ...

  10. Java 8 - 行为参数化

    前言: 以下内容来源于java8实战一书,我将里面学习的内容做一个整理,方便没空读书的小伙伴快速入门实战java8 正文: 假设一个果农收获了一园的苹果,他需要你根据他的条件筛选出满意的苹果 首先我们 ...