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. 如何给UIViewController瘦身

    本文转载至  http://www.cocoachina.com/ios/20141128/10356.html 随着程序逻辑复杂度的提高,你是否也发现了App中一些ViewController的代码 ...

  3. QTP自动化测试框架简述

    1.使用框架的原因? 框架是一组自动化测试的规范.测试脚本的基础代码,以及测试思想.惯例的集合,从而减少冗余的代码.提高代码生产率,重用性和可维护性. 2.自动化测试框架的架构 脚本层(业务组件开发) ...

  4. MongoDB C#驱动:

    MongoDB C#驱动: http://xiaosheng.me/2016/09/15/article24 http://www.cnblogs.com/wuhuacong/p/5098348.ht ...

  5. pjax + tp5,实现局部无刷新返回数据

    文件1:\application\admin\controller\Setting.php 最后一句代码:要fetch原页面 <?php namespace app\admin\controll ...

  6. Oracle中日期和时间类函数

    首先,在oracle中如何表示日期 操作日期时,应使用to_date('date','dateType')函数得到date类型,其中date为任意格式的日期,dateType指定其格式,如to_dat ...

  7. 【题解】 AT2134 Zigzag MST

    [题解]AT2134 Zigzag MST 一道MST好题 \(Anson\)有云: 要么是减少边的数量. 要么是改变连接边的方式. 那么如何减少边的数量呢?很简单,把所有不可能对答案产生贡献的边去掉 ...

  8. cordova 插件创建

    peng@PENG-PC /E/_My_File_____/_work/MyCode/myCode/cordova-workspace/plugman-test/ABCD $ npm install ...

  9. cordova 实现拨打电话-只需两步(H5)

    cordova 实现拨打电话: 第一步配置conf.xml在cordova中所有的URL Schemes 都是服从于白名单的,所以a tel 在这无法正常使用.解决方法是在项目config.xml中添 ...

  10. ios点击链接直接跳转到 App Store 指定应用下载页面

    //跳转到应用页面 NSString  *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d&quo ...