数学--数论--Find Integer(勾股数定理)
生活随笔
收集整理的這篇文章主要介紹了
数学--数论--Find Integer(勾股数定理)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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 an+bn=cn. 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 3Sample Output
4 5Source
2018中國大學生程序設計競賽 - 網絡選拔賽勾股數(shù)定理詳解
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1010; int main() {int t;scanf("%d", &t);while (t--){ll a, n;scanf("%lld%lld", &n, &a);if (n > 2 || n == 0)printf("-1 -1\n");else{ll b, c, s;if (n == 1)printf("1 %lld\n", a + 1);else if (n == 2){if (a % 2 == 1){b = a * a / 2;c = b + 1;}else{s = a * a / 2;b = s / 2 - 1;c = s / 2 + 1;}printf("%lld %lld\n", b, c);}}}return 0; }總結
以上是生活随笔為你收集整理的数学--数论--Find Integer(勾股数定理)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果全新iPhone曝光:充电口都没了!
- 下一篇: 老安卓手机有大用!放一个在车里 车子到哪