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. redis API ---python

    一, 安装配置 必须安装python3以上 配置文件自己下载,搜索名字百度 解压---->Python  --->./configure-->yum install -y zlib* ...

  2. (转)Linux基础------Shell数值计算的几种方法

    Linux基础------Shell数值计算的几种方法 原文:http://blog.csdn.net/fu_wayne/article/details/21620639 在Linux下总会遇到数值计 ...

  3. MyISAM的前缀压缩索引在索引块中的组织方式

    纯粹自己的理解,哪位大佬看到了还请指正. 首先贴一张<高性能MySQL>中的一段话: 这句话的意思是说,MyISAM使用b+树组织索引.也就是说无论索引压缩与否,组织方式一定是B+树. 下 ...

  4. 【问题记录】 Linux 安装 apache 遇到的一些问题

    以下为linux上安装apache时自己遇到的一些问题,记录在这,以后遇到时也会不定时更新... 一.安装Apache提示APR not found的解决办法 解决方法: 1. 网站 http://a ...

  5. 修改OPENSUSE 桌面快速搜索快捷键

  6. html 复选框checkbox

    统计选中复选框的个数 <html> <head> <title> </title> <script> function static_num ...

  7. BNU29139——PvZ once again——————【矩阵快速幂】

    PvZ once again Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java cla ...

  8. HDU 1166——敌兵布阵——————【线段树单点增减、区间求和】

    敌兵布阵 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  9. java 读写操作大文件 BufferedReader和RandomAccessFile

    一 老问这问题,两个都答出来算加分项? 二 具体代码如下,没什么好说的直接说对比. BufferedReader和RandomAccessFile的区别RandomAccessFile 在数据越大,性 ...

  10. 合约实战,代币合约,DAPP开发

    1. ERC20标准 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md pragma solidity ^; //定义接口 con ...