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;
}
目录
相关文章
|
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
104 0
lecture 2.2 problem set 1 and 2
1 COUNTING VOWELS   (10/10 分数) Assume s is a string of lower case characters.
1042 0
lecture 3.2 problem set 3
"Radioactive decay" is the process by which an unstable atom loses energy and emits ionizing particles - what is commonly refered to as radiation.
1140 0
|
Java
2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1060    Accepted Submission(...
1209 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...
1335 0
|
Java 人工智能 BI
2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 652    Accepted Submission(s): 267...
1193 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()]的最大长度。
930 0