Arif in Dhaka (First Love Part 2) [Uva 10294]
来源:互联网 发布:如何编写软件程序 编辑:程序博客网 时间:2024/05/16 06:13
题目地址请点击——
Arif in Dhaka (First Love Part 2)
Description [English]
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.
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.
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
Description [Chinese]
项链和手镯都是由若干珠子串成的环形首饰,区别在于手镯可以翻转,但项链不可以。
换句话说,下面两个图,如果是手镯则看做相同,项链则看做不同。
当然,不管是项链还是手镯,旋转之后一样的看做相同。
输入整数
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.
输入包含多组数据。每组数据仅一行,包含两个整数
输入结束标志为文件结束符(EOF)。
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
Solution
根据
我惊讶地发现,竟然没有打高精度就过了……
Code
#include <iostream>#include <cstdio>#define LL long longusing namespace std;LL n,t,power[101];LL gcd(LL x,LL y){ return y==0?x:(gcd(y,x%y));}int main(){ while(scanf("%lld%lld",&n,&t)!=EOF){ LL ta=0,tb=0; power[0]=1; for(LL i=1;i<=n;i++)power[i]=power[i-1]*t; for(LL i=1;i<=n;i++)ta+=power[gcd(i,n)]; if(n&1)tb=n*power[(n+1)/2]; else tb=(n*(power[n/2+1]+power[n/2]))/2; printf("%lld %lld\n",ta/n,(ta+tb)/2/n); } return 0;}
- Uva 10294 Arif in Dhaka (First Love Part 2)
- uva 10294 Arif in Dhaka (First Love Part 2)
- UVa:10294 Arif in Dhaka (First Love Part 2)
- uva 10294 - Arif in Dhaka (First Love Part 2)(置换)
- Arif in Dhaka (First Love Part 2) [Uva 10294]
- Arif in Dhaka (First Love Part 2) UVA
- 10294 - Arif in Dhaka (First Love Part 2) (数论置换)
- uva 10294 - Arif in Dhaka (First Love Part 2) Polya定理
- UVA 10294 Arif in Dhaka (First Love Part 2) polya定理
- UVa 10294 Arif in Dhaka (First Love Part 2) Polya定理
- UVA - 10294 Arif in Dhaka (First Love Part 2) (Polya定理)
- UVA 10294 Arif in Dhaka (First Love Part 2) Polya计数
- UVA 10294 Arif in Dhaka (First Love Part 2)(等价类)
- UVA Arif in Dhaka (First Love Part 2) 10294 (polya定理)
- 等价类计数(Arif in Dhaka (First Love Part 2),UVA 10294)
- uva10294 Arif in Dhaka (First Love Part 2)
- uva 10284 - Arif in Dhaka(First Love Part)等价类计数(Polya定理)
- UVA 10294 Arif in Dhaka (置换polya)
- Spring 4.x官方参考文档中文版——第21章 Web MVC框架(11)
- js 常用正则表达式表单验证代码
- Beaglebone Black———入门之改变BB-Black的CPU频率
- 00007-----连接mini2440开发板FTP
- IEtester IE6老崩溃的解决办法
- Arif in Dhaka (First Love Part 2) [Uva 10294]
- Java之静态内部类和非静态内部类的区别
- 巧用drawable
- ExtraChm的存档位置
- 【leetcode】326. Power of Three
- iOS开发调试技巧总结(持续更新中)
- Maven、eclipse与Nexus私服配置指南
- 随笔之javamail邮件发送(阿里云企业邮箱)
- C/C++函数形参传实参时值传递、指针传递、引用传递的区别