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. apache-tomcat-7.0.8\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform

    问题: apache-tomcat-7.0.8\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform 解决:jd ...

  2. bzoj4891: [Tjoi2017]龙舟

    求$\frac{b_1b_2b_3...b_m}{a_1a_2a_3...a_m}\%M$ M<=1e18,m<=100000,数据组数<=50 用pollard-rho分解M的质因 ...

  3. spring的定时任务配置(注解)

    参考博客: http://www.jb51.net/article/110541.htm http://blog.csdn.net/wxwzy738/article/details/25158787 ...

  4. WebDriverAgent原理

    传输层:HTTP/HTTPS/HSF/Socket 安全性:HTTP/HTTPS 功能.单元 性能-限流.加服务器 目的:稳定的服务的TPS摸高测试(短时间的极限,不可持续) API接口测试-施压-服 ...

  5. cursor: pin S产生原理及解决方法

    转自:http://www.dbafree.net/?p=778 今天晚上在一个比较重要的库上,CPU严重的冲了一下,导致DB响应变慢,大量应用连接timeout,紧接着LISTENER就挂了,连接数 ...

  6. js 取元素相对页面的高度和宽度

    function pos(elem) {    var x = elem.offsetLeft,  y = elem.offsetTop;    while (elem = elem.offsetPa ...

  7. [think\exception\ErrorException] glob() has been disabled for security reasons

    今天同事开发 出现了这个错误 [think\exception\ErrorException] glob() has been disabled for security reasons 打开php. ...

  8. How to create a site with AJAX enabled in MVC framework.

    How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...

  9. VB.NET 指针

    在.NET中,对指针指向数据的存储函数都封装在marshal类中,主要的函数包括:Copy.PtrToStringUni .PtrToStructure .OffsetOf.WriteXXX,Rrea ...

  10. fekit 搭建

    sudo apt-get install npmsudo apt-get install nodejs 保证npm配置正确 sudo  npm config set registry http://r ...