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;
}

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章