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

题意:给出a和b,使x+y=a,lcm(x,y)=b

题解:我们来推一波公式

x+y=a

x*y/gcd(x,y)=b

上下都除个gcd(x,y)

x/gcd(x,y)+y/gcd(x,y)=a/gcd(x,y)

x/gcd(x,y)*y/gcd(x,y)=b/gcd(x,y)

令x/gcd(x,y)为x1,y/gcd(x,y)为y1

显然x1,y1互质

所以

gcd(x1,x1+y1)=1

gcd(y1,x1+y1)=1

gcd(x1*y1,x1+y1)=1

b/gcd(x,y)与a/gcd(x,y)互质

所以gcd(x,y)=gcd(a,b)

这样就可以推出b/gcd(x,y)=b/gcd(a,b)与a/gcd(x,y)=a/gcd(a,b);

我们可以开局就求出上面的东西

问题就变成了求x+y=n,xy=m

显然小学数学推一波就稳了

代码如下:

#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lson root<<1
#define rson root<<1|1
using namespace std; long long a,b; int main()
{
while(~scanf("%lld%lld",&a,&b))
{
long long tmp=__gcd(a,b);
a/=tmp;
b/=tmp;
if(a*a-*b<) {puts("No Solution"); continue;}
long long det=(long long) (sqrt(a*a-*b));
if(det*det!=a*a-*b) {puts("No Solution"); continue;}
long long x=det+a;
long long y=a-det;
if(x&||y&) {puts("No Solution"); continue;}
x>>=;
y>>=;
if(x>y)swap(x,y);
printf("%lld %lld\n",x*tmp,y*tmp);
}
}

HDU 5974 A Simple Math Problem(数论+结论)的更多相关文章

  1. [数论] hdu 5974 A Simple Math Problem (数论gcd)

    传送门 •题意 一直整数$a,b$,有 $\left\{\begin{matrix}x+y=a\\ LCM(x*y)=b \end{matrix}\right.$ 求$x,y$ •思路 解题重点:若$ ...

  2. hdu 5974 A Simple Math Problem

    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 (数论 GCD)

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

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

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

  5. 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 ...

  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(数学题)

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

  8. 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,其 ...

  9. 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. 不同复制模式下,如何忽略某些binlog事件

    在MySQL复制中,如果slave节点上遇到错误,比如数据不存在或者主键冲突等错误时,想要忽略这些错误,可以采用以下几种方法: 1.未启用GTID模式时 只需通过设定 SQL_SLAVE_SKIP_C ...

  2. 汇编_指令_JMP

    JMP指令 JMP是汇编语言中的无条件跳转指令.无条件跳转指令可转到内存中任何程序段.转移地址可在指令中给出,也可以在寄存器中给出,或在储存器中指出. 中文名:无条件跳转指令 外文名:JMP 和调用指 ...

  3. Java-Runoob-高级教程-实例-字符串:06. Java 实例 - 字符串查找

    ylbtech-Java-Runoob-高级教程-实例-字符串:06. Java 实例 - 字符串查找 1.返回顶部 1. Java 实例 - 字符串搜索  Java 实例 以下实例使用了 Strin ...

  4. [转]JavaScript RegExp 对象参考手册

    JavaScript RegExp 对象参考手册 RegExp 对象 RegExp 对象表示正则表达式,它是对字符串执行模式匹配的强大工具. 直接量语法 /pattern/attributes 创建 ...

  5. PHP外部调用网站百度统计数据的方法详解

    目的:外部调用网站的百度统计(tongji.baidu.com)数据. 条件:1.具备调用目标网站的百度统计平台管理权限 2.PHP环境支持curl函数. 原理:同PHP小偷程序原理,通过curl函数 ...

  6. sql多表更新使用别名(小技巧)

    update     A set     A.CityRegionID=B.ParentID,     A.CityName=(select RegionName from Common_Region ...

  7. Shell 函数库

    1.为什么要定义函数库 经常使用的重复代码封装成函数文件 一般不直接执行,而是由其他脚本调用 2.编写一个函数库,该函数库实现以下几个函数. 1.加法函数:add 2.减法函数:reduce 3.乘法 ...

  8. Spring cloud Hystrix的配置属性优先级和详解

    Hystrix配置属性详解 Hystrix可以配置属性的有以下类型: Execution:控制HystrixCommand.run() 的如何执行 Fallback: 控制HystrixCommand ...

  9. WMI获取计算机信息

    On Error Resume NextstrComputer = "."strInfo = ""Set objWMIService = GetObject(& ...

  10. windows到ubuntu

    按照xmarks同步浏览器书签. mvn, copy setting.xml 最好不要用apt-get install maven, 占用/的磁盘空间 mvn -U package -P"d ...