2016ICPC-大连 A Simple Math Problem (数学)
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
InputInput 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.OutputFor 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 设gcd(x,y)=u,x=m*u,y=n*u
a/b=(mu+nu)/(m*n*u)
化简一下可以求出m,n,从而求出X,Y
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const double pi=acos(-1.0);
int n,d,x;
long long a,b,u;
long long gcd(long long a,long long b)
{
if (b==) return a;
else return gcd(b,a%b);
}
int main()
{
while(~scanf("%lld%lld",&a,&b))
{
u=gcd(a,b);
a=a/u;
b=b/u;
if ( (long long)sqrt(a*a-*b)*(long long)sqrt(a*a-*b)==a*a-*b )
{
long long t=(long long)sqrt(a*a-*b);
if ((a+t)%== && a>t) printf("%lld %lld\n",u*(a-t)/,u*(a+t)/);
else printf("No Solution\n");
} else printf("No Solution\n");
}
return ;
}
2016ICPC-大连 A Simple Math Problem (数学)的更多相关文章
- hdu5974 A Simple Math Problem(数学)
题目链接 大意:给你两个数X,YX,YX,Y,让你找两个数a,ba,ba,b,满足a+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Y. 思路:枚举gcd( ...
- FZYZ-2071 A Simple Math Problem IX
P2071 -- A Simple Math Problem IX 时间限制:1000MS 内存限制:262144KB 状态:Accepted 标签: 数学问题-博弈论 ...
- 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 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU 1757 A Simple Math Problem(矩阵)
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
- HDU 1757 A Simple Math Problem (矩阵乘法)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- 6月4 Smarty练习增删改
练习Smarty的增删改所需要用到的数据库名称:timu,xuanxiang,kemu,nandu,leixing,然后使用smarty模板将前端后后台分割开来: 主页后台页面:zhupm.php & ...
- 【其他】【PL/SQL Developer】【1】解决PL/SQL Developer过期的情况
正文: 1,开始菜单,搜索regedit,回车打开(即日常搜索电脑安装的软件的地方,regedit就是注册表) 2,按HKEY_CURRENT_USER\Software\Allround Autom ...
- org.springframework.web.bind.annotation重定向的问题
@RequestMapping(value="/redir/authcode") public ModelAndView getAuthCode(){ String authUrl ...
- poj-2369-置换
Permutations We remind that the permutation of some final set is a one-to-one mapping of the set ont ...
- sqlite3 新增数据
cx = sqlite3.connect("c:/数据库名字")#打开数据库cu = cx.cursor()cu.execute("INSERT INTO [user] ...
- docker实战系列之快速删除docker中的容器
1.停用全部运行中的容器 docker stop $(docker ps -q) 2.删除全部容器 docker rm $(docker ps -aq) 3.停用并删除容器 docker stop $ ...
- Farm Irrigation(非常有意思的并查集)
Farm Irrigation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- SQL Server“复杂”概念之理解
用惯了Oracle的人,接触SQL Server中的概念时,会觉得比较难理解,甚至感觉有点“绕”,这是因为Oracle中将某些其他数据库中存在的概念给简化了,这里就拿两个最常见的概念来举例说明:1.s ...
- 记录一下ES6扩展运算符(三点运算符)...的用法
...运算符用于操作数组,有两种层面 1. 第一个叫做 展开运算符(spread operator),作用是和字面意思一样,就是把东西展开.可以用在array和object上都行. 比如: let a ...
- ActiveMQ 配置jdbc主从
使用 jdbc 方式配置主从模式,持久化消息存放在数据库中. 在同一时刻,只有一个 master broker,master 接受客户端的连接,slave 不接受连接.当 master 因为关机而下线 ...