A Simple Math Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3646    Accepted Submission(s): 1140

Problem Description
Given two positive integers a and b,find suitable X and Y to meet the conditions:
X+Y=a
Least Common Multiple (X, Y) =b
 
Input
Input includes multiple sets of test data.Each test data occupies one line,including two positive integers a(1≤a≤2*10^4),b(1≤b≤10^9),and their meanings are shown in the description.Contains most of the 12W test cases.
 
Output
For each set of input data,output a line of two integers,representing X, Y.If you cannot find such X and Y,output one line of "No Solution"(without quotation).
 
Sample Input
6 8
798 10780
 
Sample Output
No Solution
308 490

AC代码:

 #include<bits/stdc++.h>
using namespace std; const int MAXX=; int gcd(int a,int b){
return (b>)?gcd(b,a%b):a;
} int main(){
ios::sync_with_stdio(false);
long long a,b,x,y;
while(cin>>a>>b&&a&&b){
long long temp=a;
long long l=gcd(a,b);
a/=l;
b/=l;
if(a*a-*b<){
cout<<"No Solution"<<endl;
}
else{
y=(a+sqrt(a*a-*b))/;
y*=l;
x=temp-y;
if(x*y/gcd(x,y)==b*l){
cout<<x<<" "<<y<<endl;
}
else{
cout<<"No Solution"<<endl;
}
}
}
return ;
}

HDU-5974的更多相关文章

  1. HDU 5974 A Simple Math Problem 数学题

    http://acm.hdu.edu.cn/showproblem.php?pid=5974 遇到数学题真的跪.. 题目要求 X + Y = a lcm(X, Y) = b 设c = gcd(x, y ...

  2. HDU 5974 数学

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  3. HDU 5974 A Simple Math Problem(数论+结论)

    Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...

  4. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  5. HDU 5974 A Simple Math Problem (解方程)

    题意:给定a和b,求一组满足x+y=a && lcm(x, y)=b. 析:x+y = a, lcm(x, y) = b,=>x + y = a, x * y = b * k,其 ...

  6. hdu 5974 A Simple Math Problem gcd(x,y)=gcd((x+y),lcm(x,y))

    题目链接 题意 现有\[x+y=a\\lcm(x,y)=b\]找出满足条件的正整数\(x,y\). \(a\leq 2e5,b\leq 1e9,数据组数12W\). 思路 结论 \(gcd(x,y)= ...

  7. HDU - 5974 A Simple Math Problem (数论 GCD)

    题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...

  8. hdu 5974 A Simple Math Problem(数学题)

    Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...

  9. HDU 5974 A Simple Math Problem ——(数论,大连区域赛)

    给大一的排位赛中数论的一题.好吧不会做...提供一个题解吧:http://blog.csdn.net/aozil_yang/article/details/53538854. 又学了一个新的公式..如 ...

  10. HDU 5974"A Simple Math Problem"(GCD(a,b) = GCD(a+b,ab) = 1)

    传送门 •题意 已知 $a,b$,求满足 $x+y=a\ ,\ LCM(x,y)=b$ 条件的 $x,y$: 其中,$a,b$ 为正整数,$x,y$ 为整数: •题解 关键式子:设 $a,b$ 为正整 ...

随机推荐

  1. create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理

    SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' 错误 ...

  2. mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】

    org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE ...

  3. php总结6——自定义函数、引用传值

    6.1 自定义函数 function 函数名称(参数[=默认值],参数[=默认值]...){ 函数体 [return val]; } 1) 无参数无返回 2) 有参数无返回 3) 有参数有返回 函数中 ...

  4. div+css清除浮动代码

    <style type="text/css"> .div1{ background:#000080; border:1px solid red;} .div2{ bac ...

  5. 如何查看apache配置文件路径

    我是用https://lamp.sh/安装的,apache配置文件位置在:/usr/local/apache/conf/httpd.conf如果是直接安装的apache,配置文件应该在:/etc/ht ...

  6. Java for LeetCode 092 Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  7. PAT 天梯赛 L3-008. 喊山 【BFS】

    题目链接 https://www.patest.cn/contests/gplt/L3-008 思路 因为 每个山头 最多有两个 能听到它的 临近山头 那么 我们就可以 给每个 山头 都 分配 最多两 ...

  8. [egret+pomelo]实时游戏杂记(2)

    [egret+pomelo]学习笔记(1) [egret+pomelo]学习笔记(2) [egret+pomelo]学习笔记(3) pomelo pomelo服务端介绍(game-server/con ...

  9. 图形绘制处理逻辑VC

    // 逻辑1:先从资源中读取背景资源,然后将绘图对象与DC绑定,通过绘图对象绘出背景 // 逻辑2:先从资源中读取背景资源,新建一个MEMDC,将绘图对象与MEMDC绑定,并且 // 通过绘图对象在内 ...

  10. ZOJ - 3430 Detect the Virus —— AC自动机、解码

    题目链接:https://vjudge.net/problem/ZOJ-3430 Detect the Virus Time Limit: 2 Seconds      Memory Limit: 6 ...