Ultraviolet A-10294 Arif in Dhaka (first love part 2) (polyA theorem)

Source: Internet
Author: User

Description

Problem l

Arif in Dhaka (first love part 2)

Input:Standard Input

Output:Standard output

Time limit:2 seconds

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 workingIBM) 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 onRickshaw(A Slow vehicle pulled by human power), runningDFS(By physical movement) andBFS(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 interestingNeck.pdfShop. There he finds some interestingNeck.pdf/braceletConstruction sets. He decides to buy some of them, but his programmer mind starts looking for other problems. He wants to find out how many differentNeck.pdf/braceletCan be made with a certain construction set. You are requested to help him again. The following things are true forNeck.pdf/braceletConstruction Set.

A) AllNeck.pdf/braceletConstruction sets has a frame, which hasNSlots to placeNBeads.

B) All the slots must be filled to makeNeck.pdf/bracelet.

C) There areTTypes of beads in a set.NBeads of each type are there in the box. So the total number of beads isTN(TMultipliedN), Of which exactlyNCan be used at a time.


Fig: Different Types of neckenders for t = 2 and different value of N

The figure above shows necklaces for some different valuesN(Here,TIs always2). Now let's turn out attentionsBracelets.BraceletIsNeck.pdfThat can be turned over (a junior programmer in Bangladesh says that wrist watch isNeck.pdf(Boys !!! Don't mind :-)). So forBraceletThe following two arrangements are equivalent. Similarly, all other opposite orientation or mirror images are equivalent.

So, given the description ofNeck.pdf/braceletConstruction Set you will have to determine how between different necktasks and bracelet can be formed with made with that set

Input

The input file contains several lines of input. Each line contains two positive integersN (0 <n <51)AndT (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 exceed11Digits. input is terminated by end of file.

Output

For each line of input produce one line of output which contains two round numbersNnAndNBSeparated by a single space, whereNnIs the number of total possible necklaces andNBIs the number of total possible bracelets for the corresponding input set.

Sample Input

5 2

5 3

5 4

5 5

Sample output

8

51 39

208 136

629 377

The necklace and bracelet are ring-shaped jewelry made up of several beads. The difference is that the bracelet can be flipped and rotated, but the necklace can only be rotated.

Idea: the equivalence class counting problem. Using the polyA theorem, there are two kinds of replacement, rotation and flip. If the rotation is pushed at the interval of the I beads, then this cycle has n/gcd (n, I) elements, a total of gcd (I, n) cycles, the total number of fixed points of these replications has a = t ^ gcd (I, n) {0 <= I <= n-1}; if it is flipped, it is an odd parity. When an odd number is obtained based on the symmetric axis, B = N * t ^ (n + 1)/2, in even numbers, B = n/2 * (t ^ (n/2 + 1) + t ^ (n/2 ))

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef long long ll;using namespace std;const int maxn = 105;int gcd(int a, int b) {return b == 0 ? a : gcd(b, a%b);}int main() {int n, t;while (scanf("%d%d", &n, &t) != EOF && n) {ll pow[maxn];pow[0] = 1;for (int i = 1; i <= n; i++)pow[i] = pow[i-1] * t;ll a = 0;for (int i = 0; i < n; i++)a += pow[gcd(i, n)];ll b = 0;if (n % 2 == 1)b = n * pow[(n+1)/2];else b = n / 2 * (pow[n/2+1] + pow[n/2]);printf("%lld %lld\n", a/n, (a+b)/2/n);}return 0;}


Ultraviolet A-10294 Arif in Dhaka (first love part 2) (polyA theorem)

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.