2018杭电多校:Maximum Multiple

题目描述

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.

输入

There are multiple test cases. The first line of input contains an integer  T  (1

≤T≤10^6), indicating the number of test cases. For each test case: The first line contains an integer n   (1≤n≤10^6).

输出

For each test case, output an integer denoting the maximum  xyz. If there no such integers, output                  −1  instead.

样例输入

3
1
2
3

样例输出

-1
-1
1

解题:打表找规律

#include<bits/stdc++.h>
using namespace std;
/*int main()
{
	for (int n=1;n<=1000;n++){
		int ma=0;
        for (int i=1;i<n;i++){
    	    for (int j=1;j<n;j++){
    		    for (int k=1;k<n;k++){
    			    if ((n==i+j+k)&&(n%i)==0&&n%j==0&&n%k==0){
    				    if (ma<i*j*k){
    					    ma=i*j*k;
					    }
				    }
			    }
		    }
	    }
	    if (ma)
			cout<<ma<<" ";
		else 
			cout<<"-1"<<" ";
    }
}*/
int main(){
	long long T,n;
	scanf("%lld",&T);
	while (T--){
		scanf("%lld",&n);
		if (n%3==0){
			n/=3;
			printf("%lld\n",n*n*n);
			continue;
		}
		else if  (n%4==0){
			n/=4;
			long long ans=n*n*(n*2);
			printf("%lld\n",ans);
			continue;
		}
		else 
		printf("-1\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40911499/article/details/81357190
今日推荐