HDU6298 Maximum Multiple

Maximum Multiple

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


 

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;让n = x+ y +z,并且n分别可整除x,y,z,找出x*y*z的最大值

算法:

一开始当然是想到暴力,O(n^3)的复杂度,一看数据范围.................算了吧,1e6这是开玩笑,然后想一想能不能优化一下,可以z = n-x-y,好,减少一个循环,.....................还是不够,算了吧,我选择不做了。。。。。。。。。。开玩笑开玩笑,卡到死没做出来,后面听题解。。。。找规律,有事找规律,为什么我也找了就是找不到..........果然菜得不一样,菜出新高度。。。。规律说是只有能膜3或者膜4为零的就是符合的,不是就输出-1就行了................然后补题补过了

代码:

#include<stdio.h>

int main()
{
    long long T;
    scanf("%lld",&T);
    while(T--)
    {
        long long n;
        long long ans = 0;
        scanf("%lld",&n);
        if(n%3 == 0)
        {
            ans = n/3;
            printf("%lld\n",ans*ans*ans);
        }
        else if(n%4 == 0)
        {
            printf("%lld\n",n*n*n/32);
        }
        else
        {
            printf("-1\n");
        }
    }
    return 0;
}

菜得不一样,菜出新高度。

猜你喜欢

转载自blog.csdn.net/wdaoyuanjun/article/details/81180793
今日推荐