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. 11+11=0=1+11+1.

In the second test case: − 4 2 + 9 3 = 1 = − 4 + 9 2 + 3 . \\frac−42+\\frac93=1=\\frac−4+92+3. 24+39=1=2+34+9.

In the third test case: − 18 3 + 50 5 = 4 = − 18 + 50 3 + 5 . \\frac−183+\\frac505=4=\\frac−18+503+5. 318+550=4=3+518+50.

In the fourth test case: − 4 6 + 9 9 = 1 3 = − 4 + 9 6 + 9 . \\frac−46+\\frac99=\\frac13=\\frac−4+96+9. 64+99=31=6+94+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数学计算的主要内容,如果未能解决你的问题,请参考以下文章

凸集与凸函数

Keras安装 {Keras 由浅入深}

将 Mathematica 值列表转换为布尔列表

在 Mathematica 和 MIDI 踏板事件中叠加音乐曲目

本机退出代码:-1073741510 (0xc000013a),同时使用素数检查器功能

少儿编程python哪家好?