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 (数学)的更多相关文章

  1. 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( ...

  2. FZYZ-2071 A Simple Math Problem IX

    P2071 -- A Simple Math Problem IX 时间限制:1000MS      内存限制:262144KB 状态:Accepted      标签:    数学问题-博弈论    ...

  3. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  8. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  9. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  10. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. 3月22 关于CSS

    CSS(Cascading Style Sheep 叠层样式表,作用是美化HTML网页)/*注释内容*/ 为注释的方法. 样式表的分类: 1.内联样式表 和HTML联合显示,控制精确,但是可重用性差, ...

  2. const typedef 和指针的问题(这里必须初始化的才初始化了,不必须的则没有初始化)

    这里很容易搞混: tyepdef double dou;//这里是dou是double的别名 #include<iostream> using namespace std; int mai ...

  3. swf 上传

    推荐这个博客:http://blog.csdn.net/hi_kevin/article/details/23430345 这个文章很不错,我推荐这个文章:http://leeon.me/upload ...

  4. Wannafly挑战赛22-A/B/C

    链接:https://www.nowcoder.com/acm/contest/160/A来源:牛客网 题目描述 有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,a ...

  5. oracle坏块处理记录

    1. 执行sql:select count(distinct id) from bw_fpzxx ,报错如下: ORA-01578: ORACLE 数据块损坏 (文件号 16, 块号 195428)O ...

  6. MySQL5.6复制技术(3)-MySQL主从复制线程状态转变

    一.主库线程状态(State)值 以下列表显示了主从复制中主服务器的Binlog Dump线程的State列中可能看到的最常见状态(SHOW PROCESSLIST).如果Binlog Dump线程在 ...

  7. 【数据库】SQL语句

    SQL 分为两个部分:数据操作语言(DML)和 数据定义语言(DDL).增删改查(CRUD)构成了 SQL 的 DML 部分. SELECT - 从数据库表中获取数据 SELECT 列名 FROM 表 ...

  8. 在div中放一个相同大小的svg,实际显示的位置svg偏下

    svg默认display为inline,改成block即可与div完全重合.

  9. leetcode Most Common Word——就是在考察自己实现split

    819. Most Common Word Given a paragraph and a list of banned words, return the most frequent word th ...

  10. 创建含有多module的springboot工程(八)

    创建根工程 创建一个maven 工程,其pom文件为: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version="1.0" enc ...