poj 2409 Let it Bead (polya)
来源:互联网 发布:it服务平台 编辑:程序博客网 时间:2024/05/16 18:21
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<queue>#include<map>#include<set>#define B(x) (1<<(x))using namespace std;typedef long long ll;void cmax(int& a,int b){ if(b>a)a=b; }void cmin(int& a,int b){ if(b<a)a=b; }void cmax(ll& a,ll b){ if(b>a)a=b; }void cmin(ll& a,ll b){ if(b<a)a=b; }void add(int& a,int b,int mod){ a=(a+b)%mod; }void add(ll& a,ll b,ll mod){ a=(a+b)%mod; }const int oo=0x3f3f3f3f;const ll MOD=1000000007;ll quick_pow(ll a,ll k){ ll ans=1; while(k){ if(k&1) ans=(ans*a); a=(a*a); k>>=1; } return ans;}int gcd(int a,int b){ return b ? gcd(b,a%b) : a;}int main(){ int c,n; while(scanf("%d %d",&c,&n)!=EOF){ if(n==0&&c==0)break; if(n==0){ printf("0\n"); continue; } ll ans=0; if(n&1){ ans=quick_pow(c,(n-1)/2+1)*n; for(int i=1;i<=n;i++) ans+=quick_pow(c,gcd(n,i)); }else{ ans=quick_pow(c,(n-2)/2+2)*n/2; ans+=quick_pow(c,n/2)*n/2; for(int i=1;i<=n;i++) ans+=quick_pow(c,gcd(n,i)); } cout<<ans/n/2<<endl; } return 0;}
0 0
- POj 2409 Let it Bead ----- polya计数
- POJ 2409 Let it Bead Polya定理
- POJ 2409 Let it bead 【裸polya】
- poj 2409 Let it Bead Polya计数
- poj 2409 Let it Bead (polya)
- POJ 2409-Let it Bead(Polya计数)
- POJ 2409 - Let it Bead【Polya定理】
- POJ 2409 Let it Bead ACM Polya
- POJ 2409 Let it Bead(polya)
- 【POJ 2409】 Let it Bead(Polya)
- [Polya] POJ 2409 Let it Bead
- POJ 2409 Let it Bead (Polya) .
- poj 2409 Let it Bead Polya定理
- POJ 2409 Let it Bead (Polya)
- POJ 2409 Let it Bead (Polya计数)
- poj 2409 Let it Bead(polya)
- poj 2409 Let it Bead(polya定理)
- POJ 2409 Let it Bead polya 定理 和 置换
- 查找
- 数据库调优教程(十三) MySQL数据库其他优化方法
- 第六周上机实践项目1——深复制体验(2)
- 浅谈gets()和fgets()
- 学习笔记:OC简介及面向对象(1)
- poj 2409 Let it Bead (polya)
- 一天一点MFC
- 找到了一个讲STL的博客
- Cocostudio UI进阶
- Matlab中gradient函数(梯度计算原理)
- 音乐网站Spotify将融资4亿美元,估值84亿美元
- java 异常类
- PAT A 1099. Build A Binary Search Tree (30)
- 4/12周报