HDOJ 1817 Necklace of Beads
来源:互联网 发布:flac转wav软件 mac 编辑:程序博客网 时间:2024/04/24 21:40
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1817
此题就是一个弱化版本的HDOJ 3923 Invoker,区别在于颜色数都是定死的(所以说是弱化版的),要是不会的同学可以去看看小编的另一篇博客。
#include <stdio.h>int gcd(int a,int b) {return b?gcd(b,a%b):a;}long long Pow(long long a,int b){ long long c=1; while(b){ if(b&1) c*=a; a*=a; b>>=1; } return c;}long long flip(int n){ long long ans; if(n&1) return Pow(3LL,n/2+1)*n; else{ ans=Pow(3LL,n>>1)*(n>>1); ans+=Pow(3LL,n/2+1)*(n>>1); return ans; }}long long spin(int n){ int i; long long ans=Pow(3LL,n); for(i=1;i<n;i++) ans+=Pow(3LL,gcd(n,i)); return ans;}int main(void){ int n; long long ans; while(scanf("%d",&n)==1&&n!=-1){ if(n==0){ puts("0"); continue; } if(n==1){ puts("3"); continue; } ans=flip(n); ans+=spin(n); printf("%I64d\n",ans/(n<<1)); } return 0;}
0 0
- HDOJ 1817 Necklace of Beads
- HDU 1817 - Necklace of Beads【Polya定理】
- 1286 Necklace of Beads
- POJ1286--Necklace of Beads
- Necklace of Beads
- POJ1286 Necklace of Beads
- Necklace of Beads
- Necklace of Beads POJ
- HDU1817 Necklace of Beads
- POJ 1286 Necklace of Beads
- poj 1286 Necklace of Beads
- POJ 1286 Necklace of Beads
- POJ 1286 Necklace of Beads
- POJ 1286 Necklace of Beads
- POJ 1286 Necklace of beads
- poj 1286 Necklace of Beads
- POJ 1286Necklace of Beads
- POJ--1286[Necklace of Beads] Polya定理
- 关闭 leetcode_c++:哈希:Valid Sudoku(036)
- ReactJS学习系列课程(React 性能优化及immutable使用)
- Unity圆环进度条制作
- Java中子类和父类的实例化顺序
- 使用无监督聚类的关键帧提取算法
- HDOJ 1817 Necklace of Beads
- 47、JavaScript的运动----完美运动框架的应用----放大缩小图片的实现(布局转换的实现)
- 3秒后跳转到登录界面
- cmake用法和注意
- Java类中修饰符
- Qt学习七:控件四:表格控件、网格布局、
- 14.5.1 Resizing the InnoDB System Tablespace
- MySQL详解--锁
- ScrollView嵌套ListView,ViewPager问题总结(二)