POJ 1286 Necklaces of Beads (Burnside theorem, restricted type), pojburnside

Source: Internet
Author: User

POJ 1286 Necklaces of Beads (Burnside theorem, restricted type), pojburnside

Question link: http://vjudge.net/problem/viewProblem.action? Id = 11117

Is to calculate the number of combinations after the replacement section using each equivalent case.

#include <stdio.h>#include <cstring>#include <cstdlib>#include <algorithm>#include <cmath>           using namespace std;#define lson o<<1#define rson o<<1|1#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)#define INF 200000000           typedef long long ll;ll qpow(ll a,int k){   ll ans=1;   while(k>0){     if(k&1)ans*=a;     a*=a;     k>>=1;   }   return ans;}int gcd(int a,int b){   if(a==0)return b;   return gcd(b%a,a);}ll rotation(int n){   ll rot=3;   for(int i=2;i<=n;i++){      rot+=qpow(3LL,gcd(i,n));   }   return rot;}ll reflection(int n){   ll ref=0;   if(n&1){      int cir=n/2+1;      ref=qpow(3LL,cir)*n;   }else{      ref=(ll)(n/2)*qpow(3LL,n/2);      ref+=(ll)(n/2)*qpow(3LL,1+n/2);   }   return ref;}           int main(){   int n;   while(~scanf("%d",&n) && n+1){      ll ans;      if(!n)ans=0;      else ans=(rotation(n)+reflection(n))/(2*n);      printf("%I64d\n",ans);   }   return 0;}

 



 




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.