题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大
从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求
被3整除的最大值为n^3/3^3
被4整除的最大值为n^3/(2*4*4)
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).
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
1 #include <iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 ios::sync_with_stdio(false); 8 int t; 9 cin >> t; 10 while (t--) 11 { 12 long long n; 13 cin >> n; 14 if (n % 3 == 0) 15 cout << (n / 3)*(n / 3)*(n / 3) << endl; 16 else if (n % 4 == 0) 17 cout << (n / 2)*(n / 4)*(n / 4) << endl; 18 else 19 cout << "-1" << endl; 20 } 21 return 0; 22 }