1046:Square Numbe
-
总Time Limit:
- 1000ms Memory Limit:
- 65536kB
-
Description
-
You have been given an integer b.Find the maximum integer a, subject to a * (a + b) is a square number.
Input
-
The input consists of T test cases. The number of test cases T is given in the first line of the input file. Each test case consist one integer b, one test per line.
T <= 1000, 1 <= b <= 10^9
Output
- For each test case, print the maximum a, one test per line. Sample Input
-
3 1 3 6
Sample Output
-
0 1 2
/* 规律: 当x%2==1 f(x)=(x/2)^2 ; 当x%4==0 f(x)=(x/4-1)^2 ; 当x%4==2 f(x)=2*f(x+2) */ #include<cstdio> #define ll long long ll slove (ll n) { if(n % 2 == 1) return (n/2) * (n/2); if(n % 4 == 0) return (n/4-1)*(n/4-1); if(n % 4 == 2) return 2*slove(n+2); } int main () { int T; ll n; scanf("%d", &T); while(T--) { scanf("%lld", &n); ll ans = slove(n); printf("%lld\n", ans); } return 0; }