ProblemLArifinDhaka (FirstLovePart2) Input: standardinputOutput: standardoutputTimeLimit: 2 secondsOurheroArifisnowinDhaka (Lookatproblem10244-FirstLoveifyouwanttoknowmoreaboutArif, butthatinformationisnotn
Problem L Arif inDhaka (First Love Part 2) Input: standard input Output: standard output Time Limit: 2 seconds Our hero Arif is now inDhaka (Look at problem10244-First Loveif you want to know more about Arif, but that information is not n
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 <51)< strong> And T (0 <11) < strong> As described in the problem statement. Also note that within this input range inputs will be such that no final result will exceed 11Digits. Input is terminated by end of file. <11)> <51)<>
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
To change the code, you need to handle the power of the number. Otherwise, data overflow may affect the result during the operation.
Detailed explanation of reading;
Because I can get n replicas from 1 to n, the result is divided by n.
In addition, there are n symmetric axes (I .e., n replicas) for the odd number of flipped bracelets.
N/2 + n/2 in an even number. n symmetric axes are also replaced.
(Note: n and t are greater than 0 in this question. If n is not specified in the general question, consider n = 0)
Therefore, the result is divided by 2n.
#include
#include
#include
#include
using namespace std;typedef long long LL;LL power[20];//power[i] = pow(t,i)int gcd(int x,int y){ while(x!=y) { if(x>y) x = x - y; else y = y - x; } return x;}int main(){ int n,t; while(scanf("%d%d",&n,&t)==2) { LL sum = 0; power[0] = 1; for(int i = 1;i<=n;++i) power[i] = power[i-1]*t; for(int i = 1;i<=n;++i) sum += power[gcd(i,n)]; LL sum1 = 0; if(n%2==1) { sum1 = n*power[(n+1)/2]; }else { sum1 = n/2*power[n/2+1] + n/2*power[n/2]; } printf("%lld %lld\n",sum/n,(sum + sum1)/2/n); } return 0;}