【gcd+数学证明】【HDU1722】 CAKE
来源:互联网 发布:最小公倍数算法流程图 编辑:程序博客网 时间:2024/05/02 01:56
Cake
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2077 Accepted Submission(s): 1078
Problem Description
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
Input
每行有两个数p和q.
Output
输出最少要将蛋糕切成多少块.
Sample Input
2 3
Sample Output
4Hint将蛋糕切成大小分别为1/3,1/3,1/6,1/6的四块即满足要求.当2个人来时,每人可以吃1/3+1/6=1/2 , 1/2块。当3个人来时,每人可以吃1/6+1/6=1/3 , 1/3, 1/3块。
Author
LL
Source
HZIEE 2007 Programming Contest
Recommend
lcy | We have carefully selected several similar problems for you: 1724 1798 1018 1141 1727
一开始用代数思维思考 发现十分麻烦
想到用图像去解释 如下图
题目就转换为 p+q-k k为先按p,q平均分 合成后的时候有多少公共边 (必定一条边先对齐)
即求
k1*(360/p)=k2*(360/q) 0=<k1<p 0=<k2<q;
满足条件的k1,k2组数
变形这个式子得到
且设
显然 当 k1=n1*p1(1<=n1<=gcd(p,q))
k2=n1*q1(1<=n1<=gcd(p,q))
是其中的解 解的个数最少为gcd(p,q)个
并且显然 k1/k2 必定只可能是p1/q1的整数倍 解的个数最多为gcd(p,q)个
所以满足条件的k1,k2只有gcd(p,q)个
所以ans=p+q-gcd(p,q)
1 0
- 【gcd+数学证明】【HDU1722】 CAKE
- 【HDU1722】Cake(gcd)
- 【GCD(最大公约数)】HDU1722-Cake
- hdu1722 cake
- hdu1722 - cake
- hdu1722 cake
- hdu1722 Cake
- hdu1722--cake
- HDU1722 cake
- hdu1722 gcd
- HDU 1722 Cake (GCD+数学)
- gcd 证明
- hdu1722
- hdu1722
- hdu1722
- hdu 1722 Cake(gcd)
- hdoj 1722 Cake 【GCD】
- Cake (gcd)
- 网易2012校园招聘笔试题目
- Check if a binary tree is subtree of another binary tree
- Fixtures在Django测试中的使用
- If you are given two traversal sequences, can you construct the binary tree?
- Map-Reduce: Shuffle and Sort
- 【gcd+数学证明】【HDU1722】 CAKE
- javaScript中的事件对象event
- Stanford机器学习---第一讲. Linear Regression with one variable
- 为你的rm加个回收站(ubuntu)
- 112 - Tree Summing
- No orientation specified, and the default is horizontal. This is a common source of bugs when childr
- Oracle Security Alert for CVE-2014-7169
- HDU3966(树链剖分(点权)入门)链分治
- 高斯滤波器