问题传送门:https://vjudge.net/contest/320779#problem/D
介绍一个名词:奇偶数列法则
Key part:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define ll long long int main() { int t; ll a,b,c,n; scanf("%d",&t); while(t--) { scanf("%lld%lld",&n,&a); if(n>2 || n==0) printf("-1 -1 "); else if(n==1) printf("1 %lld ",a+1); else //an equation:a^2+b^2=c^2,we know a,find b,c? { //a=2*m--->b=m^2-1,c=m^2+1 ll m=a/2; //a=2*m+1--->b=2*m*(m+1),c=2*m*(m+1)+1 m>=1 if(a&1) { b=2*m*(m+1); c=2*m*(m+1)+1; } else { b=m*m-1; c=m*m+1; } printf("%lld %lld ",b,c); } } }