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$ 为正整 ...
随机推荐
- Bootstrap-CL:页面标题
ylbtech-Bootstrap-CL:页面标题 1.返回顶部 1. Bootstrap 页面标题(Page Header) 页面标题(Page Header)是个不错的功能,它会在网页标题四周添加 ...
- CCproxy 设置代理服务器。
CCproxy 设置代理服务器. 通过代理服务器上网,出口IP就固定成代理服务器的IP 设置安装比较简单,直接去ccproxy官网下载就行 如果服务器是公网服务器,记得在设置,高级里面的网络中,把禁止 ...
- Spring Boot使用@Scheduled定时器任务
摘要: Spring Boot之使用@Scheduled定时器任务 假设我们已经搭建好了一个基于Spring Boot项目,首先我们要在Application中设置启用定时任务功能@EnableS ...
- uva-110-没有for循环的排序
题意:看输出就懂了,暴力枚举题,字符串最大长度是8,所有长度等于8的长度是8!=1x2x3x4x5x6x7x8=40320,数据量比较小的.只是枚举的方向比较怪异,如下,长度等于3的串 a ab,ba ...
- socket与http的区别
---------------------------------------------------------------------------------------------------- ...
- tesseract-ocr训练方法
tesseract-ocr有2和3两个版本,不同版本训练方法稍有不同. 第3版本的训练方法官版教程在这里:TrainingTesseract3 第2版的训练方法官版教程在这里:TrainingTess ...
- 跟我学算法-opencv加载,修改,保存
#include<opencv2/opencv.hpp> #include<iostream> #include<math.h> using namespace c ...
- 【常见CPU架构对比】维基百科
Comparison of instruction set architectures https://en.wikipedia.org/wiki/Comparison_of_instruction_ ...
- WebService之SOAP
SOAP(Simple Object Access Protocol),它是一种标准消息传递协议,通常是Web Service的事实标准.SOAP是以XML为基础,SOAP消息格式是由XML Sche ...
- 4-在windon10上mysql安装与图形化管理
安装及可能遇到的问题: 1.windows10上安装mysql(详细步骤 https://blog.csdn.net/zhouzezhou/article/details/52446608 2. 在 ...