Problem Description
Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤106).
Output
For each test case, output an integer denoting the maximum xyz. If there no such integers, output −1 instead.
Sample Input
3 1 2 3
Sample Output
-1 -1 1
简单数学题
include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d" , &T);
while(T --)
{
int n ;
scanf("%d" , &n);
if(n < 3)
{
printf("-1\n");
continue;
}
long long temp = n / 3;
if(temp * 3 == n)
{
temp = temp * temp * temp;
printf("%lld\n" , temp);
//cout << temp * temp * temp << endl;
continue;
}
else
{
int flag = 0;
long long a = n / 2 ;
long long b = n / 4 ;
long long c = n / 4;
if(a + b + c == n)
{
a = a * b * c;
printf("%lld\n" , a);
//cout << a * b * c << endl;
continue;
}
printf("-1\n");
//cout << -1 << endl;
}
}
return 0;
}