A Restoring Numbers

1人阅读 评论(0) 收藏 举报
分类:

A. Restoring Numbers
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Pavel had two positive integers a and b. He found their sum s and greatest common divisor g, and forgot a and b after that. Help him to restore the original numbers.

Input

A single line contains two integers s and g (1 ≤ s ≤ 109, 1 ≤ g ≤ 109) — sum and greatest common divisor of the numbers a and b.

Output

If Pavel made a mistake and there are no such numbers a and b, output a single number  - 1.

Otherwise, output two positive integers a and b on a single line, separated by a space. If there are multiple possible solutions, output any of them.

Examples
input
Copy
6 2
output
Copy
4 2
input
Copy
7 2
output
Copy
-1


题意:输入是s,g,是原始的两个数的和,最大公因子。让你求原来的两个数,如果没有就输出-1.
题解:规律    刚开始想暴力的,但是学长提示了,说考思想,可以几行代码出来。后来不停的验证,模拟,发现了一个规律,输入的和减去最大公因子,如果是最大公因子的倍数就有原始的数,不然就没有。但是考虑4 4这种两个数都相等的情况,因为4-4=0,然后0%4==0的,会输出YES的,所以还要判断一下。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,r,c;
    cin>>a>>b;
    if((a-b)%b==0&&a!=b)
        cout<<a-b<<" "<<b;
    else cout<<-1;
}


查看评论

Restoring Numbers

属于构造反证 先设A[I] = 0 , 那么我们就可以出b[i], 并且0 a[i] = w[i][1] - b[1]  并且 -k 所以    -k 如果所有的 w[i][j] - a[i...
  • u013570474
  • u013570474
  • 2015-02-05 01:12:01
  • 240

[CF509D] Restoring Numbers && 构造

构造的时候把a0视为0  构造出可能有负数的序列a b 再构造出矩阵e e[i][j] = |a[i] + b[j] - w[i][j]| 若e都为0 则k取大于w中所有数字的值即可 若e[i]...
  • shiyukun1998
  • shiyukun1998
  • 2015-02-03 20:39:56
  • 269

codeforces 509D Restoring Numbers

codeforces 509D Restoring Numbers 题意: v[i][j]=(a[i]+b[j])%k 现在给出n*m矩阵v[][], 求a[],b[]和k, 任意一种情况都...
  • whai362
  • whai362
  • 2015-02-14 10:04:15
  • 660

Restoring Number

Pavel had two positive integers a and b. He found their sum s and greatest common divisor g, and for...
  • cgtllp1
  • cgtllp1
  • 2018-03-30 21:29:56
  • 25

Codeforces Round #451 (Div. 2) F. Restoring the Expression(哈希)

F. Restoring the ExpressionProblem Statement     A correct expression of the form a+b=c was writte...
  • Effervescence
  • Effervescence
  • 2017-12-18 22:46:09
  • 152

zoj 3965 Binary Tree Restoring(* dfs)

Binary Tree Restoring Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge Given t...
  • u014665013
  • u014665013
  • 2017-04-25 21:47:59
  • 841

Codeforces Gym 101466 - 2017 ACM-ICPC, Universidad Nacional de Colombia Programming Contest

A. Gaby And Addition time limit per test 6.0 s memory limit per test 1024 MB input ...
  • sinat_35406909
  • sinat_35406909
  • 2018-01-22 19:41:14
  • 300

题目1442:A sequence of numbers

// 只有等比数列和等差数列。。。等差数列直接用公式求。。。等比数列用二分求幂法。。。 // 不要忘了%200907。。。注意整数类型。。。 #include #define M  200907...
  • Wss0130
  • Wss0130
  • 2014-03-01 20:24:19
  • 1072

Mongodb从0到1系列八: 备份与恢复

Mongodb从0到1系列一:下载、安装、启动、停止 Mongodb从0到1系列二:数据库与集合操作文档、增删改查 Mongodb从0到1系列三: 条件查询、大小写 Mongodb从0到1系列四: L...
  • qingsong3333
  • qingsong3333
  • 2017-07-28 00:31:19
  • 610

codeforces940 C. Phone Numbers【贪心】

C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes And where the ar...
  • nobleman__
  • nobleman__
  • 2018-02-24 23:19:52
  • 223
    个人资料
    持之以恒
    等级:
    访问量: 9945
    积分: 2139
    排名: 2万+
    访客
    Flag Counter
    文章存档