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. ASP.NET动态网站制作(7)-- JS(2)

    前言:这节课是JS的第二节课,主要是JS中的控制语句. 内容: 1.条件语句:  (1)比较操作符:==,!=,>,>=,<,<=.字符串大小写转换:toUpperCase() ...

  2. iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)

     本文转载至  http://blog.csdn.net/totogo2010/article/details/8637430       1.介绍 有的博友看了上篇博文iOS界面-仿网易新闻左侧抽屉 ...

  3. python 基础 6.0 异常的常用形式

    一. 异常   异常既是一个时间,该事件会在程序执行过程中发生,影响了程序的正常执行.一般情况下,在python无法正常处理程序时就会发生一个异常.异常是python对象,表示一个错误.当python ...

  4. 【BZOJ3091】城市旅行 LCT

    [BZOJ3091]城市旅行 Description Input Output Sample Input 4 5 1 3 2 5 1 2 1 3 2 4 4 2 4 1 2 4 2 3 4 3 1 4 ...

  5. ZOJ 3502 Contest <状态压缩 概率 DP>

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...

  6. jQuery学习笔记(8)--表格筛选

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

  7. Moving Computation is Cheaper than Moving Data

    https://hadoop.apache.org/docs/r1.2.1/hdfs_design.html Introduction The Hadoop Distributed File Syst ...

  8. wxPython的Refresh与事件双重响应

    #!/usr/bin/env python import wx class DoubleEventFrame(wx.Frame): def __init__(self, parent, id): wx ...

  9. mapreduce的一个模版

    import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import j ...

  10. c# &与&& 和 |与||的区别(转载)

    &:按位与,对两个条件都进行判断&&:逻辑与,只要一个条件满足,另外一个条件就不会执行 同理:|:按位或,对两个条件都进行判断||:逻辑或,只要一个条件满足,另外一个条件就不会 ...