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. Android 超高仿微信图片选择器 图片该这么载入

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/39943731,本文出自:[张鸿洋的博客] 1.概述 关于手机图片载入器,在当今像 ...

  2. LoadRunner hits per second 深入理解

    Hits per Second Graph The Hits per Second graph shows the number of HTTP requests made by Vusers to ...

  3. HTML5(石头剪刀布游戏开发)

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. TCP(Socket基础编程)

    1.TCP特点: 面向连接.可靠安全.传输量大.速度较慢 2.socket编程主要依靠两个类:socket .serversocket example1:客户端可以不停输入字符串,服务端返回字符串的大 ...

  5. Objective-c中的delegate浅析

    delegate初探 在ios开发中,我们常常会用到类似例如以下的对话框: 因此,例如以下这段代码我们也就非常熟悉了: - (IBAction)showSheet:(id)sender { UIAct ...

  6. 获取系统 SID

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/hadstj/article/details/26399533 获取系统 SID ((gwmi win ...

  7. 【Leetcode-easy】String to Integer(atoi)

    题目要求:字符串->整型 * 1. 首先需要丢弃字符串前面的空格. * 2. 然后可能有正负号(注意只取一个,如果有多个正负号,那么说这个字符串是无法转换的,返回0.比如测试用例里就有个“+-2 ...

  8. mysql优化之 EXPLAIN(一)

    数据库优化最常用的命令就是用explain查看一下写的sql是否用到了索引: 如: (root@localhost) [akapp]>explain select * from sc_activ ...

  9. 基于springboot的RestTemplate、okhttp和HttpClient对比

    1.HttpClient:代码复杂,还得操心资源回收等.代码很复杂,冗余代码多,不建议直接使用. 2.RestTemplate: 是 Spring 提供的用于访问Rest服务的客户端, RestTem ...

  10. Linux (ubuntu和redhat) 常用命令及细节

    1.关闭防火墙(Ubuntu) sudo ufw disable 2.vi 拷贝   参考http://blog.sina.com.cn/s/blog_601331150100ecfr.html 一) ...