Sicily 1793. Numbers
来源:互联网 发布:三维模型数据网络发布 编辑:程序博客网 时间:2024/05/07 15:44
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Given the greatest common divisor(GCD) and the least common multiple(LCM) of two integers a and b (a <= b), please find the minimum of b-a.
Input
Input may consist of several test data sets. For each data set, it can be format as below: There is just one line containing two integers, the GCD and the LCM, both are between [1, 10^9].
Input is ended by GCD = LCM = 0.
Output
For each data set, output one integer representing the minimum difference of a and b can be found, and then output a, then b, separated with only one space. If more than one pair of a and b can be found, output the one which has minimum a.
Sample Input
6 36
1 35
0 0
Sample Output
6 12 18
2 5 7
n(≧▽≦)n Just do it!
#include <iostream>#include <cmath>using namespace std;int get_GCD(int num1, int num2){ if (num1 % num2 != 0) { return get_GCD(num2, num1 % num2); } else return num2;}int main(){ int GCD, LCM, a, b; while (cin >> GCD >> LCM && (GCD || LCM)) { //// 暴力搜寻,从最接近的位置开始寻找 for (b = ceil(sqrtf(LCM * GCD)); b <= LCM; b++){ if (LCM * GCD % b == 0){ a = LCM * GCD / b; if (get_GCD(a, b) == GCD){ break; } } } cout << b - a << " " << a << " " << b << endl; } return 0;}
- Sicily 1793. Numbers
- Sicily 1793. Numbers
- Sicily 1793. Numbers
- Sicily 1050. Numbers & Letters
- Sicily 1050. Numbers & Letters
- Sicily 1050 Numbers & Letters
- Sicily 1158. Pick numbers
- sicily 1050 Numbers & Letters
- Sicily 1158 Pick numbers
- sicily 1158.Pick numbers
- Sicily 1050. Numbers & Letters
- Sicily 1050. Numbers & Letters
- Sicily 1158 Pick numbers
- Sicily 1454. Pseudoprime numbers
- Sicily 1050. Numbers & Letters
- sicily 1050.Numbers & Letters
- sicily 1050. Numbers & Letters
- sicily 1050. Numbers & Letters
- javascript学习笔记之二
- Cable TV Network-POJ1966图的连通度
- cocos2dx v3.9 与SpriteFrameCache和AnimationCache之间的对话
- 级联映射关系的分页查询ManyToMany的notIn子查询subquery实现。notMember 、notExist
- Activity你需要知道的一切
- Sicily 1793. Numbers
- IOS开发系列——UIView专题之一:UIWindow篇【整理】
- Git使用教程详解之三 Git分支
- python入门笔记(Day4)--map,reduce
- Ascii、 unicode、 utf-8 互转(WideCharToMultiByte和MultiByteToWideChar函数的用法)
- iOS performSelector: withObject: 详细教程
- 破解win2003“终端服务器授权”激活许可证!
- 迷宫最短路径
- Android Studio debug使用release的签名