HDU 5974 A Simple Math Problem(数论+结论)
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(数论+结论)的更多相关文章
- [数论] hdu 5974 A Simple Math Problem (数论gcd)
传送门 •题意 一直整数$a,b$,有 $\left\{\begin{matrix}x+y=a\\ LCM(x*y)=b \end{matrix}\right.$ 求$x,y$ •思路 解题重点:若$ ...
- hdu 5974 A Simple Math Problem
A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 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 ...
- HDU 5974 A Simple Math Problem ——(数论,大连区域赛)
给大一的排位赛中数论的一题.好吧不会做...提供一个题解吧:http://blog.csdn.net/aozil_yang/article/details/53538854. 又学了一个新的公式..如 ...
- 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 ...
- 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)= ...
- hdu 5974 A Simple Math Problem(数学题)
Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...
- 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,其 ...
- 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$ 为正整 ...
随机推荐
- mysqlinsert触发器的创建
CREATE DEFINER=`wpsuper`@`%` TRIGGER `o2oinsert` BEFORE INSERT ON `t_s_o2o`FOR EACH ROW begin set Ne ...
- "废物利用"也抄袭——“完全”DIY"绘图仪"<二、下位机程序设计>
就不说怎么组装了吧,一把辛酸泪.说程序,因为这有两把辛酸泪……一把给下位机的C代码一把为了VB.NET的图像处理……不过就上上一篇说的,它们可以正确运行了,并且今天克服了Arduino上电过程中步进电 ...
- Microsoft SQL Server on Linux破解 2G内存限制
首先,贴上微软官方安装方法,大家按照官方的操作就行. 微软官方安装方法 相信很多同学遇到一个问题就是: sqlservr: This program requires a machine with a ...
- Solr聚合查询
1 分组查询 概述:Solr常用的分组查询有两种,Facet分组和Group分组,分别以下列出这两种查询: 1.1 Facet分组 solr种以导航为目的的查询结果成为facet,在用户 ...
- win10开启开发人员模式
工具: win10 方法如下: 1.在Windows10系统桌面,点击开始菜单,然后在弹出窗口中选择“设置”菜单项 2.在打开的设置窗口中,选择“更新和安全”图标,并点击打开更新和安全窗口 3.在打开 ...
- 使用python读取大文件
python中读取数据的时候有几种方法,无非是read,readline,readlings和xreadlines几种方法,在几种方法中,read和xreadlines可以作为迭代器使用,从而在读取大 ...
- 跟我学算法-PCA(降维)基本原理推导
Pca首先 1.对数据进行去均值 2.构造一个基本的协方差矩阵1/m(X)*X^T 3对协方差矩阵进行变化,得到对角化矩阵,即对角化上有数值,其他位置上的数为0(协方差为0),即求特征值和特征向量的过 ...
- CentOS Linux最常用命令及快捷键整理
最近一直在对CentOS系统进行各种体验,为方便自己也方便他人,整理了Linux常用命令及快捷键,不过其实大多和DOS是一样的,只是命令的表达上可能有点儿不一样. 常用Linux命令: 文件和目录: ...
- mysql安装版卸载,解压版安装
卸载:https://blog.csdn.net/cxy_summer/article/details/70142322 解压版安装:https://blog.csdn.net/recky_wiers ...
- SpringBoot简单理解
SpringBoot 一.特点:1.默认大于配置,不需要大量配置文件,没有web.xml,拥有可运行的Application类. 2.一般通过java代码配置,而尽量少使用xml配置. 3.maven ...