【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)
題干:
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 3Sample Output
4 5解題報告:
? ? ? ? 根據(jù)費馬大定理的結(jié)論,用奇偶構(gòu)造法求出勾股定理中另外兩個數(shù)。
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 ; }?
知識點:(勾股定理的構(gòu)造)
總結(jié)
以上是生活随笔為你收集整理的【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不怕删错了!微信iOS版8.0.24更新
- 下一篇: 用上骁龙旗舰芯:曝华为MatePad P