2018中国大学生程序设计竞赛 - 网络选拔赛 hdu Find Integer 数论
2024-09-01 05:04:46
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
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;
}
最新文章
- java初始化
- 【My Life】写在年末, 我的2013
- [原创]win10 命令行出现问号而且无法chcp 936
- Spark BlockManager的通信及内存占用分析(源码阅读九)
- Java之properties文件读取
- update
- 安装 python psutil 包
- sublime text主要快捷键列表
- HTML-002-弹出对话框
- java.util.concurrent包API学习笔记
- ";ORA-00942: 表或视图不存在 ";的原因和解决方法[转]
- C# 获取Get请求返回
- QUIC协议原理分析(转)
- Java开发笔记(五)数值变量的类型
- python 加密 hashlib与hmac模块
- Jmeter(六)Jmeter脚本包含要素及书写习惯
- Linux终端小技巧
- python全栈 流程控制;while 循环 格式化输出 运算符 及编码
- 课程一(Neural Networks and Deep Learning)总结——2、Deep Neural Networks
- 开发人员必备的几款bug管理工具