CodeForces - 1584A Mathematical Addition数学计算
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1584A Mathematical Addition数学计算相关的知识,希望对你有一定的参考价值。
A. Mathematical Addition
time limit per test 1 second
memory limit per test 256 megabytes
Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form:
You are given two positive integers u and v, find any pair of integers (not necessarily positive) x, y, such that:
x
u
+
y
v
=
x
+
y
u
+
v
.
\\fracxu+\\fracyv=\\fracx+yu+v.
ux+vy=u+vx+y.
The solution x=0, y=0 is forbidden, so you should find any solution with (x,y)≠(0,0).
Please help Ivan to solve some equations of this form.
Input
The first line contains a single integer t (1≤t≤103) — the number of test cases. The next lines contain descriptions of test cases.
The only line of each test case contains two integers u and v (1≤u,v≤109) — the parameters of the equation.
Output
For each test case print two integers x, y — a possible solution to the equation. It should be satisfied that −1018≤x,y≤1018 and (x,y)≠(0,0).
We can show that an answer always exists. If there are multiple possible solutions you can print any.
Example
input
4
1 1
2 3
3 5
6 9
output
-1 1
-4 9
-18 50
-4 9
Note
In the first test case:
−
1
1
+
1
1
=
0
=
−
1
+
1
1
+
1
.
\\frac−11+\\frac11=0=\\frac−1+11+1.
1−1+11=0=1+1−1+1.
In the second test case: − 4 2 + 9 3 = 1 = − 4 + 9 2 + 3 . \\frac−42+\\frac93=1=\\frac−4+92+3. 2−4+39=1=2+3−4+9.
In the third test case: − 18 3 + 50 5 = 4 = − 18 + 50 3 + 5 . \\frac−183+\\frac505=4=\\frac−18+503+5. 3−18+550=4=3+5−18+50.
In the fourth test case: − 4 6 + 9 9 = 1 3 = − 4 + 9 6 + 9 . \\frac−46+\\frac99=\\frac13=\\frac−4+96+9. 6−4+99=31=6+9−4+9.
问题链接:CodeForces - 1584A Mathematical Addition
问题简述:(略)
问题分析:(略)
AC的C语言程序如下:
/* CodeForces - 1584A Mathematical Addition */
#include <stdio.h>
int main()
int t;
scanf("%d", &t);
while (t--)
long long u, v;
scanf("%lld%lld", &u, &v);
printf("%lld %lld\\n", - u * u, v * v);
return 0;
以上是关于CodeForces - 1584A Mathematical Addition数学计算的主要内容,如果未能解决你的问题,请参考以下文章
在 Mathematica 和 MIDI 踏板事件中叠加音乐曲目