• POJ 1286 Necklace of Beads


    // 3中颜色的n个珠子 问有多少种不同数量 旋转和翻转后相同算一种 
    // 先考虑旋转 转i格 循环节 gcd(i,n)
    // 翻转的话 n为奇数 每种翻转循环节 n/2+1
    // n为偶数 n/2的循环节为 n/2 n/2的循环节为 (n-2)/2 +2
    // 最后用 polya定理
    #include <iostream> #include <stdio.h> using namespace std; #define LL long long LL Pow(LL a,LL b) { LL t=1; for(;b;b>>=1) { if(b&1) t=t*a; a=a*a; } return t; } int gcd(int a,int b) { int r; while(r=a%b){a=b;b=r;} return b; } int main() { int i,n; LL ans; //printf("%lld ",Pow(2,10)); while(scanf("%d",&n),~n) { if(!n){printf("0 ");continue;} ans=0; for(i=1;i<=n;i++) ans+=Pow(3,gcd(i,n)); // printf("%lld ",ans); if(n&1) ans+=n*Pow(3,n/2+1); else { ans+=n/2*Pow(3,n/2); ans+=n/2*Pow(3,n/2+1); } printf("%lld ",ans/n/2); } return 0; }
  • 相关阅读:
    项目前期
    酒店平台预订管理系统
    毕业论文管理系统化————面向对象方法
    项目前期
    打印出10道四则运算
    软件工程
    酒店预定管理系统
    毕业论文管理系统
    酒店预定管理系统
    android
  • 原文地址:https://www.cnblogs.com/372465774y/p/3633691.html
Copyright © 2020-2023  润新知