UVA 10294 Arif in Dhaka (First Love Part 2) Polya计数

题目链接

Polya计数入门题

10294 Arif in Dhaka (First Love Part 2)

Our hero Arif is now in Dhaka (Look at problem 10244 – First Love if you want to know more about
Arif, but that information is not necessary for this problem. In short, Arif is a brilliant programmer
working at IBM) and he is looking for his first love. Days pass by but his destiny theory is not working
anymore, which means that he is yet to meet his first love. He then decides to roam around Dhaka on
a rickshaw (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 his probability of reaching
his goal. While roaming around Dhaka he discovers an interesting necklace shop. There he finds some
interesting necklace/bracelet construction sets. He decides to buy some of them, but his programmer
mind starts looking for other problems. He wants to find out how many different necklace/bracelet can
be made with a certain construction set. You are requested to help him again. The following things
are true for a necklace/bracelet construction set.
a) All necklace/bracelet construction sets has a frame, which has N slots 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. N beads of each type are there in the box. So the total
number of beads is t · N (t multiplied by N), of which exactly N can be used at a time.
Fig. 1: Different types of necklace for t = 2 and different value of N
The figure above shows necklaces for some different values of N (Here, t is always 2). Now let’s
turn out attentions to bracelets. A bracelet is a necklace that can be turned over (A junior programmer
in Bangladesh says that wrist watch is a necklace (Boys!!! Don’t mind :-))). So for a bracelet the
following two arrangements are equivalent. Similarly, all other opposite orientation or mirror images
are equivalent.
Universidad de Valladolid OJ: 10294 – Arif in Dhaka (First Love Part 2) 2/2
So, given the description of a necklace/bracelet construction set you will have to determine how
many different necklace and bracelet can be formed with made with that set
Input
The input file contains several lines of input. Each line contains two positive integers N (0 < N < 51)
and t (0 < t < 11) as described in the problem statement. Also note that within this input range inputs
will be such that no final result will exceed 11 digits. Input is terminated by end of file.
Output
For each line of input produce one line of output which contains two round numbers NN and NB
separated by a single space, where NN is the number of total possible necklaces and NB is the number
of total possible bracelets for the corresponding input set.
Sample Input
5 2
5 3
5 4
5 5
Sample Output
8 8
51 39
208 136
629 377

/* ***********************************************
Author        :CKboss
Created Time  :2015年05月06日 星期三 15时32分53秒
File Name     :UVA10294.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;

LL n,t;
LL Pow[60];

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

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

    while(scanf("%lld%lld",&n,&t)!=EOF)
    {

        Pow[0]=1LL;
        for(int i=1;i<=n+3;i++) Pow[i]=Pow[i-1]*t;

        LL a=0LL,b=0LL;
        for(LL i=0;i<n;i++) a+=Pow[gcd(n,i)];

        if(n%2==0)
        {
            b=(n/2)*(Pow[n/2]+Pow[n/2+1]);
        }
        else
        {
            b=n*Pow[(n+1)/2];
        }

        printf("%lld %lld\n",a/n,(a+b)/2/n);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值