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$ 为正整 ...
随机推荐
- Remi 安装源
Remi repository 是包含最新版本 PHP 和 MySQL 包的 Linux 源,由 Remi 提供维护.有个这个源之后,使用 YUM 安装或更新 PHP.MySQL.phpMyAdmin ...
- html5播放mp4视频代码
1.nginx支持flv和mp4格式播放 默认yum安装nginx centos7安装nginx时候应该是默认安装nginx_mod_h264_streaming模块的 # nginx -V查看是否安 ...
- python 可视化 词云图
文本挖掘及可视化知识链接 我的代码: # -*- coding: utf-8 -*- from pandas import read_csv import numpy as np from sklea ...
- M3截止阶段小结
python知识点总结1.copy模块中深浅拷贝copy() deepcopy()2.__new__ 方法参数 def __new__(cls, *args, **kwargs): ...
- windows拖动文件到Ubuntu
只需要安装 sudo apt install lrzsz
- 3_bootsrap布局容器
3.布局容器 BootStrap必须需要至少一个布局容器,才能为页面内容进行封装和方便的样式控制. 相当于一个画板. 帮助手册位置:全局CSS样式------->概览------->布局容 ...
- curl获取响应时间
1.开启gzip请求curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte 2.监控网页的响应时间curl -o /dev/nu ...
- Pthreads n 体问题
▶ <并行程序设计导论>第六章中讨论了 n 体问题,分别使用了 MPI,Pthreads,OpenMP 来进行实现,这里是 Pthreads 的代码,分为基本算法和简化算法(引力计算量为基 ...
- 迷你MVVM框架 avalonjs 1.3.4发布
发现一个以前从来没发现的大BUG,紧急发布此版本. fix getEachProxy BUG,此BUG会导致监控数组在删除某元素然后再添加元素时出现问题. avalon ms-on-*绑定添加一个钩子 ...
- ColorMask
[ColorMask] When using multiple render target (MRT) rendering, it is possible to set up different co ...