日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 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 (费马大定理 + 奇偶数列法构造勾股定理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。