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 a^n+b^n=c^n.

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>=3时必然无解,因此只需讨论n==2的情况

参见:http://tieba.baidu.com/p/108936816

code:

#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll b[40005];
ll c[40005];
int id=1;
ll num[10005];
void init()
{
for(ll aa=3;aa<=40000;aa++)
{
if(aa%2)
{
b[aa]=(aa/2)*(aa/2)+(aa/2+1)*(aa/2+1)-1;
c[aa]=(aa/2)*(aa/2)+(aa/2+1)*(aa/2+1);
}
else
{
b[aa]=(aa/2)*(aa/2)-1;
c[aa]=(aa/2)*(aa/2)+1;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif // ONLIN
init(); int t;
cin>>t;
ll a,n;
while(t--)
{
scanf("%lld%lld",&n,&a);
if(n>=3)
{
printf("-1 -1\n");continue;
}
else if(n==0)
{
printf("-1 -1\n");
}
else if(n==1)
{
printf("1 %lld\n",a+1);
}
else if(n==2)
{
printf("%lld %lld\n",b[a],c[a]);
}
} return 0;
}

2018中国大学生程序设计竞赛 - 网络选拔赛 Find Integer的更多相关文章

  1. 2018中国大学生程序设计竞赛 - 网络选拔赛---Find Integer!--hdu6441

    问题传送门:https://vjudge.net/contest/320779#problem/D 介绍一个名词:奇偶数列法则 Key part: #include<iostream> # ...

  2. 2018中国大学生程序设计竞赛 - 网络选拔赛 1001 - Buy and Resell 【优先队列维护最小堆+贪心】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6438 Buy and Resell Time Limit: 2000/1000 MS (Java/O ...

  3. 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...

  4. 2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation 【dfs+树上两点距离和】

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  5. HDU - 6440 Dream 2018中国大学生程序设计竞赛 - 网络选拔赛

    给定的\(p\)是素数,要求给定一个加法运算表和乘法运算表,使\((m+n)^p = m^p +n^p(0 \leq m,n < p)\). 因为给定的p是素数,根据费马小定理得 \((m+n) ...

  6. 2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法

    http://acm.hdu.edu.cn/showproblem.php?pid=6440 题意:让你重新定义任意一对数的乘法和加法结果(输出乘法口诀表和加法口诀表),使得m^p+n^p==(m+n ...

  7. hdu6444 2018中国大学生程序设计竞赛 - 网络选拔赛 1007 Neko's loop

    Neko's loop Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...

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

    A - Buy and Resell 题意:给出n个交易点,每次能够选择买或者卖,求获得最大利润 思路:维护两个优先队列,一个是卖,一个是替换,当价格差相同时,优先替换,因为次数要最少 #includ ...

  9. 2018中国大学生程序设计竞赛 - 网络选拔赛 4 - Find Integer 【费马大定理+构造勾股数】

    Find Integer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

随机推荐

  1. MyBatis 安装和配置

    在这里我们使用 MyBatis 开发一个简单的 Java 项目(默认你已安装JDK和MySQL及会使用Maven的基本操作),可以与上一篇通过底层操作数据进行比较 1.新建表 students,插入数 ...

  2. 大数据之Hadoop完全分布式集群搭建

    1.准备阶段 1.1.新建三台虚拟机 Hadoop完全分市式集群是典型的主从架构(master-slave),一般需要使用多台服务器来组建.我们准备3台服务器(关闭防火墙.静态IP.主机名称).如果没 ...

  3. java解析json字符串详解(两种方法)

    一.使用JSONObject来解析JSON数据官方提供的,所以不需要导入第三方jar包:直接上代码,如下 private void parseJSONWithJSONObject(String Jso ...

  4. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  5. 从入门到自闭之Python内置函数

    内置函数一 eval:执行字符串类型的代码 exac:执行字符串社类型的代码 eval与exac 禁止使用 hash()作用就是区分可变数据类型与不可变数据类型 # print(hash(" ...

  6. Django重写用户模型报错has no attribute 'USERNAME_FIELD'

    目录 Django重写用户模型报错has no attribute 'USERNAME_FIELD' 在重写用户模型时报错:AttributeError: type object 'UserProfi ...

  7. Idea java 程序打jar包(maven)

    1.准备好控制台程序 2.引用的项目打包(公共类接口) 3.开发打包 点击运行 打包结果如下

  8. nginx redirect ignore port 两层nginx跳转忽略了端口

    问题: 两层nginx做代理,第一层:nginx:将9087->代理到80端口,第二层:将80端口->流量打到我们的代码上,结果在代码中拿到的链接不带9087端口,则代码中发生跳转的时候, ...

  9. Tomcat各版本及源码包下载

    Tomcat各版本及源码包下载 1.百度 Tomcat 进入官网2.Tomcat 官网地址:http://tomcat.apache.org/3.所有 Tomcat 版本及源码包下载地址:https: ...

  10. 移远模组-BC95-工作模式之间关系

    三种连接状态下,均可发送上行数据( CoAP/UDP): IDLE 下发送数据, 模块会进入 CONNECT 状态: PSM 下发送是数据会唤醒模块, 进入 CONNECT,或者当 TAU(TAU 的 ...