Find Integer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

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
 
分析:根据费马大定理:n>2时无解
  只要考虑n=0,1,2
  n=0时,无解
  n=1时,随意构造两个数满足a+b=c
  n=2时,随意构造一组勾股数满足a*a+b*b=c*c
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
int main() {
ios::sync_with_stdio(0);
ll T;
scanf("%lld",&T);
while( T -- ) {
ll n, a, b, c;
scanf("%lld%lld",&n,&a);
if( n >= 3 || n == 0 ) {
printf("-1 -1\n");
}
else if( n == 1 ) {
printf("1 %lld\n",a+1);
}
else {
ll h = 1;
while( a%2 == 0 ) {
a = a/2;
h = h*2;
}
ll s, t;
s = a;
t = 1;
b = (s*s-t*t)/2;
c = (s*s+t*t)/2;
b = b*h;
c = c*h;
printf("%lld %lld\n",b,c);
}
}
return 0;
}

  

最新文章

  1. java初始化
  2. 【My Life】写在年末, 我的2013
  3. [原创]win10 命令行出现问号而且无法chcp 936
  4. Spark BlockManager的通信及内存占用分析(源码阅读九)
  5. Java之properties文件读取
  6. update
  7. 安装 python psutil 包
  8. sublime text主要快捷键列表
  9. HTML-002-弹出对话框
  10. java.util.concurrent包API学习笔记
  11. &quot;ORA-00942: 表或视图不存在 &quot;的原因和解决方法[转]
  12. C# 获取Get请求返回
  13. QUIC协议原理分析(转)
  14. Java开发笔记(五)数值变量的类型
  15. python 加密 hashlib与hmac模块
  16. Jmeter(六)Jmeter脚本包含要素及书写习惯
  17. Linux终端小技巧
  18. python全栈 流程控制;while 循环 格式化输出 运算符 及编码
  19. 课程一(Neural Networks and Deep Learning)总结——2、Deep Neural Networks
  20. 开发人员必备的几款bug管理工具

热门文章

  1. 放出一批jsp图书管理系统图书借阅系统源码代码运行
  2. 单元测试python unittest
  3. Java学习多线程第二天
  4. [实践]activemq安全设置 设置admin的用户名和密码
  5. JS鼠标吸粉特效
  6. 8.7 day28 网络编程 socket套接字 半连接池 通信循环 粘包问题 struct模块
  7. 前端面试题集锦(一)之HTML部分
  8. Java 在spring cloud中使用Redis,spring boot同样适用
  9. MySQL高可用架构:mysql+keepalived实现
  10. jmeter之beanshell使用