HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple

简介: HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple

Maximum Multiple

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0


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


解题思路:题目中 “|” 是整除的意思。

3:1 1 1

4:1 1 2

如果有解,一定满足 n%3==0 || n%4==0,否则输出 -1。

若是:n%3==0,n/3 n/3 n/3;

若是:n%4==0,n/4 n/4 n/2;

而且 n%3 的情况要比 n%4 大。


AC 代码


/

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
    int T; scanf("%d",&T);
    ll n;
    while(T-- && ~scanf("%lld",&n))
    {
        ll rs;
        if(n%3==0) rs=n/3*n/3*n/3;
        else if(n%4==0) rs=n/2*n/4*n/4;
        else rs=-1;
        printf("%lld\n",rs);
    }
    return 0;
}
目录
相关文章
《Towards A Fault-Tolerant Speaker Verification System A Regularization Approach To Reduce The Condition Number》电子版地址
Towards A Fault-Tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
89 0
《Towards A Fault-Tolerant Speaker Verification System A Regularization Approach To Reduce The Condition Number》电子版地址
|
Java
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
130 0
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
113 0
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
106 0
|
语音技术 机器学习/深度学习 开发者
语音顶会Interspeech 论文解读|Towards A Fault-tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
Interspeech是世界上规模最大,最全面的顶级语音领域会议,本文为Siqi Zheng, Gang Liu, Hongbin Suo, Yun Lei的入选论文
语音顶会Interspeech 论文解读|Towards A Fault-tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
|
Java
2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 127    Accepted Submission(s): 20 Pro...
1416 0
2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1539    Accepted Submission(s...
1339 0
2015 Multi-University Training Contest 5 1009 MZL&#39;s Border
MZL's Border  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5351   Mean:  给出一个类似斐波那契数列的字符串序列,要你求给出的f[n]字符串中截取前m位的字符串s中s[1...i] = s[s.size()-i+1....s.size()]的最大长度。
931 0