题干:

people in USSS love math very much, and there is a famous math problem .

give you two integers nn,aa,you are required to find 22 integers bb,cc such that anan+bn=cnbn=cn.

Input

one line contains one integer TT;(1≤T≤1000000)(1≤T≤1000000)

next TT lines contains two integers nn,aa;(0≤n≤1000(0≤n≤1000,000000,000,3≤a≤40000)000,3≤a≤40000)

Output

print two integers bb,cc if bb,cc exits;(1≤b,c≤1000(1≤b,c≤1000,000000,000)000);

else print two integers -1 -1 instead.

Sample Input

1
2 3

Sample Output

4 5

解题报告:

根据费马大定理的结论,用奇偶构造法求出勾股定理中另外两个数。

AC代码:

#include<bits/stdc++.h>using namespace std;int main()
{int t;cin>>t;while(t--) {int n,a;scanf("%d%d",&n,&a);if(n > 2 || n==0) {puts("-1 -1");}else if(n == 1) {printf("1 %d\n",a+1);}else {if(a&1) {int tmp = (a-1)/2;printf("%d %d\n",2*tmp*tmp + 2*tmp,2*tmp*tmp+2*tmp+1);}else {int tmp = a/2 - 1;printf("%d %d\n",tmp*tmp + 2*tmp,tmp*tmp + 2*tmp + 2);}}}return 0 ;
}

知识点:(勾股定理的构造)

【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)相关推荐

  1. HDU 6441(费马大定理+奇偶数列法)

    思路:由费马大定理知a^n+b^n=c^n当n>2时无整数解,所以n==0和n>2时输出-1 -1,n==1时输出1,a+1,n==2时,由奇偶数列法 (https://blog.csdn ...

  2. HDU 6441 Find Integer 【费马大定理】

    传送门:HDU 6441 Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...

  3. 【2018-CCPC青岛网赛】 HDU - 6441 Find Integer

    [2018-CCPC青岛网赛] HDU - 6441 Find Integer 源链接: HDU - 6441 文源 :Blog 题意 已知等式,a^n + b ^ n = c ^ n,题目中给出 a ...

  4. hdu.6441 Find Integer

    hdu.6441 Find Integer 思路:费马大定理+勾股定理. 费马大定理内容:an+bn=cn,(n>2)a^n+b^n=c^n,(n>2)an+bn=cn,(n>2)时 ...

  5. Find Integer - hdu6441 - 费马大定理+奇偶数列法则

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=6441 思路: 输入n, 若n>2由费马大定理知无解.输出-1 -1,n=0时也无解,输出-1 - ...

  6. 【hdu】6441 Find Integer - 费马大定理

    Find Integer 题解: 根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的. 再假设当 n=0 时,a^0=1.题目中说到 (1≤b,c≤1000,00 ...

  7. HDU 6441 Find Integer(费马大定理)

    people in USSS love math very much, and there is a famous math problem . give you two integers n,a,y ...

  8. HDU 6441 Find Integer(数论)

    Description 给出n,an,an,a,求一组b,cb,cb,c使得an+bn=cna^n+b^n=c^nan+bn=cn Input 第一行一整数TTT表示用例组数,每组用例输入两个整数n, ...

  9. HDU 6441 Find Integer

    题目传送门 代码: #include<bits/stdc++.h> using namespace std;int main(){int T;scanf("%d",&a ...

最新文章

  1. 著名统计学家Donald B. Rubin:机器是否可以思考甚至具有意识?
  2. 制作mac风格 例子(一)
  3. 拉力赛 (Standard IO)
  4. 计算机函授本科题库,计算机应用基础函授本科考试题库
  5. 苹果app商品定价_【知乎问答】苹果 App Store 新推出的 1 元或 3 元定价对开发者有什么影响?...
  6. rbac权限管理5张表_Laravel5实现RBAC权限管理
  7. php是什么电器元件,电阻器是电子、电器设备中常使用的一种基本电子元件
  8. android webview_在 Flutter 中使用 WebView
  9. 每天一个linux命令(16):witch命令
  10. 实验4-1-4 求整数的位数及各位数字之和 (15 分)
  11. android 输入框失去焦点,AutoCompleteTextView默认首次失去焦点
  12. 使用php建立评论系统
  13. CISCO常用配置命令
  14. lisp方格网法计算土方量_CASS方格网法如何计算土方量
  15. 7654劫持火狐解决办法
  16. 学python历程中
  17. 20135203齐岳 信息安全系统设计基础第四周学习总结
  18. linux clk驱动框架
  19. 网络天才网页中文版_网络天才电脑版
  20. java switch 条件_Java ——if条件语句 switch语句

热门文章

  1. php 函数 数组 难学,php 数组的常用函数
  2. python多线程编程_Python 多线程编程
  3. php html登陆逻辑,保持演示文稿(HTML)和逻辑(PHP)分开
  4. win8配置mysql5.6,win8.1(64位) apache2.4.3+php5.6.3+mysql5.6安装
  5. 赋值给集合_ArrayList集合源码
  6. 665C. Simple Strings
  7. java中除了跟数据相关的知识_Java的基本数据类型及知识介绍
  8. python电子英汉词典显示_python网页抓取之英汉字典
  9. A20修改串口设备文件
  10. WinCE OAL中的OEMIoControl函数