数学--数论--Find Integer(勾股数定理)
2024-09-07 19:25:26
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;
}
最新文章
- 英文论文中i.e.,e.g.,etc.,viz.的简要小结
- thinkphp框架验证码验证一次
- html插入链接
- Qt5 程序发布打包
- STL中的优先级队列(priority_queue)的自己实现priqueue
- PAT乙级真题1006. 换个格式输出整数 (15)(解题)
- JS高级——闭包
- MFC界面相关(彩色工具栏)
- Linux命令学习篇0——原产地
- cookie创建,删除
- javaSE 第77节课
- Oracle死锁情况
- 微信公众号开发 VS2015本地调试
- electron应用以管理员权限启动
- 简单理解 RPC(转载)
- Angular 简单的Post
- [React] 01 - Intro: javaScript library for building user interfaces
- (转)实现一个cache装饰器,实现过期可清除功能
- 使用vbox构建局域网络
- Jmeter的接口测试简介
热门文章
- 数据结构和算法(Golang实现)(30)查找算法-2-3-4树和普通红黑树
- linux中忘记了mysql的root用户的密码怎么办?
- Mysql 临时表+视图
- 浏览器判断兼容IE
- 7.3 java 成员变量和局部变量区别
- python3(四)list tuple
- MySQL中group_concat函数 --- 很有用的一个用来查询出所有group by 分组后所有 同组内的 内容
- web.xml中通过contextConfigLocation的读取spring的配置文件
- Tomcat启动过程原理详解 -- 非常的报错:涉及了2个web.xml等文件的加载流程
- TensorFlow保存、加载模型参数 | 原理描述及踩坑经验总结