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
题目:n=x+y+z x|n,y|n,z|n,求xyz的最大值 思路:三个数,还都能被整除,基本就分成三类 1/2 1/4 1/4 、1/2 1/3 1/6 、1/3 1/3 1/3 因为求乘积最大值所以1/6直接舍去,直接按能被3或4整除的情况讨论即可 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n,i,t,temp,ans1,ans2,k;scanf("%lld",&t);while(t--){ scanf("%lld",&n);if(n%3&&n%4)printf("-1\n");else{ if(n%3==0&&n%4==0){ temp=n/3;ans1=temp*temp*temp;temp=n/4;k=n/2;ans2=temp*temp*k;if(ans1<ans2)printf("%lld\n",ans2);elseprintf("%lld\n",ans1);}else if(n%3==0&&n%4!=0){ temp=n/3;//cout<<temp<<endl;; ans1=temp*temp*temp;printf("%lld\n",ans1);}else if(n%4==0&&n%3!=0){ temp=n/4;k=n/2;ans2=temp*temp*k;printf("%lld\n",ans2);}}} }