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. ruby里面的属性访问器

    和ios的@property一样 attr_accessor 表明是示例的getter和setter 下面的是rails的扩展,裸体class里面用,貌似会报错 cattr_accessor 表明是类 ...

  2. emacs之自动完成括号

    网上抄来的问题不少,看emacswiki,用autopairs即可 emacsConfig/autopair-setting.el (require 'autopair) (autopair-glob ...

  3. 安装wamp 缺少msvcr100.dll

    在一台新电脑上安装wampsever 这是百度上的解决方案,http://jingyan.baidu.com/article/0320e2c1eb49681b87507ba4.html 本人亲测 第一 ...

  4. C++ 构造函数_析构函数

    什么是析构函数 如果说构造函数是对象来到世间的第一声哭泣,那么析构函数就是对象死亡前的最后遗言. 析构函数在对象销毁时会被自动调用,完成的任务是归还系统的资源. 特性: 1.如果没有自定义的析构函数, ...

  5. 利用PHP实现页面跳转同时POST传参,CURL不行

    function payto(){ echo "<form style='display:none;' id='form1' name='form1' method='post' ac ...

  6. 管理Linux服务器的用户和组

    管理Linux服务器的用户和组 Linux操作系统是一个多用户多任务的操作系统,允许多个用户同时登录到系统,使用系统资源. 为了使所有用户的工作顺利进行,保护每个用户的文件和进程,规范每个用户的权限, ...

  7. canvas设置渐变

    canvas设置渐变 方法 createLinearGradient(x1, y1, x2, y2) 线性渐变 createRadialGradient(x1, y1, r1, x2, y2, r2) ...

  8. python 爬预警没解析前的

  9. 「小程序JAVA实战」小程序搜索功能(55)

    转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxusousuogongneng54/ 通过用户搜索热销词,将热销词添加到 ...

  10. 记一次微信小程序开发

    之前在网上看到博客园新闻服务开放接口,因为自己本身有看博客园IT新闻的习惯,为了能随时随地简洁方便的浏览新闻,于是萌生了一个利用开放API开发一个微信小程序的想法. 1. mpvue初探 平时技术栈有 ...