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 ...
随机推荐
- Git将本地项目上传到GitHub
本文转载于:https://segmentfault.com/a/1190000011909294 https://www.cnblogs.com/cxk1995/p/5800196.html 我们使 ...
- 1002. Find Common Characters查找常用字符
参考:https://leetcode.com/problems/find-common-characters/discuss/247573/C%2B%2B-O(n)-or-O(1)-two-vect ...
- 创建型模式篇(单例模式Single Pattern)
一.单例模式(Singleton Pattern) 单例模式要求一个类只能有一个实例,并且提供了一个全局的访问点. 比如说,中国主席的职位是Singleton,法律规定主席选举,任何时间只能有一个主席 ...
- Hadoop---目录结构介绍
Hadoop---目录结构介绍 1.Hadoop目录结构 1.一级目录介绍 2.etc详解: 3sbin 4.bin 5.share 6.一个数独测试 2.hadoop的历史 3. Ha ...
- Charles破解网站收藏(持续更新)
1. 在这个网站(http://charles.iiilab.com/)下载破解文件 charles.jar 2. 替换掉原文件夹里的charles.jar Mac: /Applications/Ch ...
- etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3
1● alb 2● write =====>rait 1● alg 2● pain 痛,疼痛 1● alt 2● high 高 1 ...
- 原 spring-boot工程中,jpa下hibernate的ddl-auto的各种属性
jpa: hibernate: ddl-auto: create ddl-auto:create----每次运行该程序,没有表格会新建表格,表内有数据会清空 ddl-auto:create-d ...
- 转 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
MATLAB Coder可以从MATLAB代码生成独立的.可读性强.可移植的C/C++代码. http://www.mathworks.cn/products/matlab-coder/ 使用MATL ...
- Intellij下Jquery中文乱码
今天在用Jquery+Ajax实现检查用户名是否可用的功能时,意外的发生了乱码,谷歌了很久后终于找到了解决办法: 把js文件复制一份在桌面 用记事本打开,另存为UTF-8格式 复制粘贴回去,覆盖之前的 ...
- 逆袭之旅DAY16.东软实训.Oracle.序列
2018-07-12 14:07:44 序列 序列1.创建序列create sequence 序列名 [increment by n] ---步长 [start with n] ---序列的起始值 序 ...