Find Integer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6597    Accepted Submission(s): 1852
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、 a 求解方程 a^n + b^n = c^n;

解题思路:

根据费马大定理 n > 2 时无解;

n == 0 时 无解;

n == 1 时 a, 1, a+1;

n == 2 时,根据已知 a 构造一组勾股数

当 a 为 大于 4 的偶数 2*k 时:  b = k^2 - 1, c = k^2 + 1;

当 a 为 大于 1 的奇数 2*k +1 时: b = 2*k^2 + 2*k, c = 2*n^2 + 2*n + 1;

code:

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std; const int MAXN = 1e9;
int N, a;
int main()
{
int T, b, c, k;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &N, &a);
if(N> || N==) printf("-1 -1\n");
else if(N==) printf("%d %d\n", , a+);
if(N==)
{
if(a%){
k = (a-)/;
b = *k*k+*k;
c = *k*k+*k+;
printf("%d %d\n", b, c);
}
else
{
k = a/;
b = k*k-;
c = k*k+;
printf("%d %d\n", b, c);
}
}
}
return ;
}

2018中国大学生程序设计竞赛 - 网络选拔赛 4 - Find Integer 【费马大定理+构造勾股数】的更多相关文章

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

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

  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中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟

    Dream Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

随机推荐

  1. js中的table导出成Excel表格

    首先判断手否是IE,原因在于IE导出我用的是ActiveXObject,判断的方式很简单,只需要拿到window.navigator.userAgent即可进行判断,代码如下 function get ...

  2. zabbix 监控 tomcat

    一, 脚本监控文件 #!/bin/bash # @Function # Find out the highest cpu consumed threads of java, and print the ...

  3. python 爬虫系列05--丑事百科

    丑事百科爬虫 import re import requests def parse_page(url): headers = { 'User-Agent':'user-agent: Mozilla/ ...

  4. opencv + ffmpeg

    opencv2.4.13 与 ffmepg 3.0 一起是可以安装成功的.注意编译ffmpeg时, ./configure   --enable-shared 否则会报错. 另外,把以上组合换成ope ...

  5. Tortoise SVN安装后右键没有菜单的解决方法

    最近换了WIN7的操作系统,感觉用起来爽极了,于是开始一个个装软件,最让我头疼的就是安装SVN,安装没有问题,完成后却无法显示右键菜单,开始同事也帮我找原因,以为是我设置问题或者哪里阻止了程序,还以为 ...

  6. 【python爬虫】利用selenium和Chrome浏览器进行自动化网页搜索与浏览

    功能简介:利用利用selenium和Chrome浏览器,让其自动打开百度页面,并设置为每页显示50条,接着在百度的搜索框中输入selenium,进行查询.然后再打开的页面中选中“Selenium - ...

  7. 程序包com.sun.image.codec.jpeg不存在

    在pox.xml中引入依赖 <dependency><groupId>rt</groupId><artifactId>rt</artifactId ...

  8. 创建Django项目时,settings的静态文件的配置

    STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), )

  9. js控制5秒返回指定界面,或上一个界面

    js控制5秒返回指定界面,代码如下 <head> <meta http-equiv="Content-Type" content="text/html; ...

  10. springboot如何实现微信登录,前期准备

    现在网站用微信登录真的是很多,那么具体是怎么实现的呢? 首先介绍的是微信开放平台,我们如果需要微信登录或者支付都需要在上面注册一个账号,用这个账号去为我们的网站申请的话,需要用到企业资料(家里有营业执 ...