Description”Let it Bead” company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It’s a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.

A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.

``````#include<stdio.h>
using namespace std;
long long M,N;
long long gcd(long long x,long long y){
return y==0? x : gcd(y,x%y);
}
long long fast_pow(long long m,long long n){
long long ans=1;
for(;n;n>>=1,m=m*m)
if(n&1)
ans=ans*m;
return ans;
}
int main(){
while(~scanf("%d%d",&M,&N)&&(M||N)){
long long sum=0;
for(int i=1;i<=N;i++){
long long temp=gcd(N,i);
sum+=fast_pow(M,temp);
}
if(N&1){
sum+=N*fast_pow(M,(N+1)/2);
}
else{
sum+=(N/2)*(fast_pow(M,(N+2)/2));
sum+=(N/2)*(fast_pow(M,N/2));
}
sum=sum/(2*N);
printf("%lld\n",sum);
}
//system("pause");
return 0;
}``````