传送门

•题意

一直整数$a,b$,有

$\left\{\begin{matrix}
x+y=a\\
LCM(x*y)=b
\end{matrix}\right.$

求$x,y$

•思路

解题重点:若$gcd(p,q)=1$,则$gcd(p+q,pq)=1$

设$gcd(x,y)=g$,令$p=\frac{x}{g},q=\frac{y}{g}$,$p,q$互素

则$\left\{\begin{matrix}
x+y=p*g+q*g=(p+q)g=a\\
LCM(x,y)=\frac{xy}{g}=p*q*g=b
\end{matrix}\right.$

由于$p,q$互素,所以$gcd(a+b,ab)=gcd((p+q)*g,pqg)=g$

所以的$gcd(x,y)=g=gcd(a+b,ab)$

$\left\{\begin{matrix}
x+y=a\\
xy=bgcd(a,b)
\end{matrix}\right.$

然后解方程组就ok了,

不过要注意输出$x,y$先后顺序

小的在前,大的在后,虽然题目里没说,但因为这wa了

•代码

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x,y,a,b;
int main()
{
while(~scanf("%lld%lld",&a,&b))
{
bool flag=true;
ll gcd=__gcd(a,b);
ll ssub=a*a-*b*gcd;
ll sub=sqrt(ssub);
if(ssub!=sub*sub)
flag=false;
if((a+sub)%)
flag=false;
x=(a+sub)/;
y=a-x;
if(flag)
printf("%lld %lld\n",min(x,y),max(x,y));
else
puts("No Solution");
}
}

[数论] hdu 5974 A Simple Math Problem (数论gcd)的更多相关文章

  1. HDU 5974 A Simple Math Problem(数论+结论)

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

  2. 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$ 为正整 ...

  3. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

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

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

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

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

  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(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)= ...

随机推荐

  1. 2019-3-21-win10-uwp-修改图片质量压缩图片

    title author date CreateTime categories win10 uwp 修改图片质量压缩图片 lindexi 2019-03-21 15:29:20 +0800 2019- ...

  2. TIJ——Chapter Fourteen:Type Information

    Runtime type information(RTTI) allows you to discover and use type information while a program is ru ...

  3. MUI - 为textarea添加语音输入和清除的功能

    为textarea添加语音输入和清除的功能 mui支持input输入框语音输入和清除的功能,只需要添加相关css类即可. http://www.cnblogs.com/phillyx/ 代码如下 &l ...

  4. 阿里云发布 Redis 5.0 缓存服务:全新 Stream 数据类型带来不一样缓存体验

    4月24日,阿里云正式宣布推出全新 Redis 5.0 版本云数据库缓存服务,据悉该服务完全兼容 4.0 及早期版本,继承了其一贯的安全,稳定,高效等特点并带来了全新的 Stream 数据结构及多项优 ...

  5. Android中后台线程如何与UI线程交互

    我想关于这个话题已经有很多前辈讨论过了.今天算是一次学习总结吧. 在android的设计思想中,为了确保用户顺滑的操作体验.一些耗时的任务不能够在UI线程中运行,像访问网络就属于这类任务.因此我们必须 ...

  6. @bzoj - 4378@ [POI2015] Pustynia

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a,每个数都在 1 到 10^ ...

  7. @51nod - 1196/1197/1198@ 字符串的数量

    目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @accepted code@ @details@ @description@ ...

  8. linux自动挂载NTFS格式移动硬盘

    转自:http://blog.163.com/cmh_lj/blog/static/100812304201252522119264/ 由于移动硬盘还有不少的资料,刚插入移动硬盘的时候发现只能自动挂载 ...

  9. H3C TCP封装

  10. halcon坐标转换(机器人坐标转换用)

    #图像坐标r:=[431, 355, 507, 53, 507]c:=[505, 543, 316, 127, 883]#物理坐标(例如机器人坐标)r1:=[0, 2.0, -2.0, 10, -2. ...