目录

 

Maximum Multiple

 题目解释:

解题思路:

ac代码:


Maximum Multiple

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3469    Accepted Submission(s): 1429

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

 题目解释:


三个正整数x,y,z,使得x+y+z=n,且n/x,n/y,n/z都能整出,输出xyz的最大乘积

 

解题思路:


举一些例子,可以发现

3=1+1+1;xyz=1;

4=1+1+2;xyz=2;

如果n能整除3,xyz=(n/3)*(n/3)*(n/3);

如果n能整除4,xyz=(n/4)*(n/4)*(n/2);

其他情况xyz都是-1;

又一个可能出错的点:比如12,即可以整除3也可以整除4,但是4*4*4>3*3*6,所以优先判断是否可以整除3

 

ac代码:


#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long int
int main()
{
    ll t,n;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        if(n%3==0)
            printf("%lld\n",(n/3)*(n/3)*(n/3));
        else if(n%4==0)
            printf("%lld\n",(n/4)*(n/4)*(n/2));
        else
            puts("-1");
    }
    return 0;
}