###### 【Burnside引理】【Polya定理】Arif in Dhaka

Problem L

Arif in Dhaka (First LovePart 2)

Input: standard input

Output: standard output

Time Limit: 2 seconds

Our hero Arif is now in Dhaka (Lookat problem 10244– First Love if you want to know more about Arif, but thatinformation is not necessary for this problem. In short, Arif is a brilliantprogrammer working atIBM) and he islooking for his first love. Days pass by but his destiny theory is not workinganymore, which means that he is yet to meet his first love. He then decides toroam around Dhaka on arickshaw(A slow vehicle pulled by human power), running DFS (by physical movement) and BFS(with his eyes) on every corner of the street and market places to increase hisprobability of reaching his goal. While roaming around Dhaka he discovers an interestingnecklace shop. There he finds someinteresting necklace/braceletconstruction sets. He decides to buy some of them, but his programmer mindstarts looking for other problems. He wants to find out how many differentnecklace/bracelet can be made with acertain construction set. You are requested to help him again. The followingthings are true for anecklace/braceletconstruction set.

a)      All necklace/braceletconstruction sets has a frame, which hasNslots to place N beads.

b)      All the slots must be filled to make a necklace/bracelet.

c)      There are t types of beads in a set. Nbeads of each type are there in the box. So the total number of beads istN (t multiplied by N), ofwhich exactlyN can be used at atime.

Fig: Different types ofnecklace for t=2 and different value of N

The figure above shows necklaces for some different values of N (Here,t is always 2). Nowlet’s turn out attentions tobracelets.A bracelet is a necklacethat can be turned over (A junior programmer in Bangladesh says that wristwatch is anecklace (Boys!!! Don’tmind :-))). So for a bracelet thefollowing two arrangements are equivalent. Similarly, all other oppositeorientation or mirror images are equivalent.

So, given the description of a necklace/braceletconstruction set you will have to determine how many different necklace andbracelet can be formed with made with that set

Input

The input file contains severallines of input. Each line contains two positive integersN(0<N<51)and t(0<t<11) as described inthe problem statement. Also note that within this input range inputs will besuch that no final result will exceed11digits. Input is terminated by end of file.

Output

For each line of input produceone line of output which contains two round numbersNN and NB separated by asingle space, where NN is the numberof total possible necklaces and NBis the number of total possible bracelets for the corresponding input set.

Sample Input

5 2

5 3

5 4

5 5

SampleOutput

8 8

51 39

208 136

629 377

#include <cstdio>
#include <iostream>
using std::cin;
using std::cout;

typedef long long ll;
ll power[27];

int gcd(int a,int b)
{
//cout << "gcd(" << a << "," << b << ")=";
while (b)
{
int t = b;
b = a%b;
a = t;
}
//cout << a << '\n';
return a;
}

int main()
{
freopen("10294.in","r",stdin);
freopen("10294.out","w",stdout);

int n,t;
while (scanf("%d%d",&n,&t)!=EOF)
{
power[0] = 1;
for (int i=1;i<=n;i++)
power[i] = power[i-1] * t;

ll a = 0;
ll b = 0;
for (int i=0;i<n;i++)
{
a += power[gcd(i,n)];
}
if (n & 1)
{
b = n * power[(n+1)>>1];
}
else
{
b = n/2*power[n/2+1] + n/2*power[n/2];
}

cout << a/n << " " << (a+b)/2/n << "\n";
}
return 0;
}

#### SQLServer数据库高级实战视频课程

2017年03月15日 20:42

#### Burnside引理与Polya定理

2015-07-26 16:03:19

#### polya/burnside定理入门

2016-10-06 14:46:47

#### ACM_置换群 burnside引理 Polya定理

2016-06-27 14:06:01

#### 组合数学常用内容——Polya定理+Burnside引理

2017-05-07 11:15:00

#### 群、置换、循环-课件

2010年12月02日 343KB 下载

#### burnside引理+polya计数法小结

2017-02-09 00:13:31

#### Burnside引理和polay计数学习笔记

2016-09-15 00:23:25

#### 初涉OI中的群论(Burnside引理和Polya定理)

2018-01-12 09:36:47

#### uva 10294 - Arif in Dhaka (First Love Part 2)(置换)

2014-08-13 10:35:47

## 不良信息举报

【Burnside引理】【Polya定理】Arif in Dhaka