Problem Description

people in USSS love math very much, and there is a famous math problem
give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn.
Input
one line contains one integer T;(1≤T≤1000000)
next T lines contains two integers n,a;(0≤n≤1000,000,000,3≤a≤40000)

Output

print two integers b,c if b,c exits;(1≤b,c≤1000,000,000)
else print two integers -1 -1 instead.

Sample Input

1
2 3

Sample Output

4 5

Source

2018中国大学生程序设计竞赛 - 网络选拔赛

勾股数定理详解

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
ll a, n;
scanf("%lld%lld", &n, &a);
if (n > 2 || n == 0)
printf("-1 -1\n");
else
{
ll b, c, s;
if (n == 1)
printf("1 %lld\n", a + 1);
else if (n == 2)
{
if (a % 2 == 1)
{
b = a * a / 2;
c = b + 1;
}
else
{
s = a * a / 2;
b = s / 2 - 1;
c = s / 2 + 1;
}
printf("%lld %lld\n", b, c);
}
}
}
return 0;
}

最新文章

  1. 英文论文中i.e.,e.g.,etc.,viz.的简要小结
  2. thinkphp框架验证码验证一次
  3. html插入链接
  4. Qt5 程序发布打包
  5. STL中的优先级队列(priority_queue)的自己实现priqueue
  6. PAT乙级真题1006. 换个格式输出整数 (15)(解题)
  7. JS高级——闭包
  8. MFC界面相关(彩色工具栏)
  9. Linux命令学习篇0——原产地
  10. cookie创建,删除
  11. javaSE 第77节课
  12. Oracle死锁情况
  13. 微信公众号开发 VS2015本地调试
  14. electron应用以管理员权限启动
  15. 简单理解 RPC(转载)
  16. Angular 简单的Post
  17. [React] 01 - Intro: javaScript library for building user interfaces
  18. (转)实现一个cache装饰器,实现过期可清除功能
  19. 使用vbox构建局域网络
  20. Jmeter的接口测试简介

热门文章

  1. 数据结构和算法(Golang实现)(30)查找算法-2-3-4树和普通红黑树
  2. linux中忘记了mysql的root用户的密码怎么办?
  3. Mysql 临时表+视图
  4. 浏览器判断兼容IE
  5. 7.3 java 成员变量和局部变量区别
  6. python3(四)list tuple
  7. MySQL中group_concat函数 --- 很有用的一个用来查询出所有group by 分组后所有 同组内的 内容
  8. web.xml中通过contextConfigLocation的读取spring的配置文件
  9. Tomcat启动过程原理详解 -- 非常的报错:涉及了2个web.xml等文件的加载流程
  10. TensorFlow保存、加载模型参数 | 原理描述及踩坑经验总结