HDU6298 Maximum Multiple (多校第一场1001)

Posted acmerszl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU6298 Maximum Multiple (多校第一场1001)相关的知识,希望对你有一定的参考价值。

Maximum Multiple

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


Problem Description
Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, xn, yn, zn and xyz is maximum.
 

 

Input
There are multiple test cases. The first line of input contains an integer T (1T106), indicating the number of test cases. For each test case:
The first line contains an integer n (1n106).
 

 

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, 需要满足  x|n,  y|n,   z|n (整除关系),输出xyz的最大值,若不存在,输出-1
 
设 n/x = r     n/y = s      n/z = t  ,    r  <=  s  <=  t
 
所以1/r + 1/s + 1/t = 1
 
所以r <= 3
 
当r=3    s,t = (3,3)
当r=2    s,t = (4, 4) , (3, 6) 
 
所以三种情况
n/3   n/3   n/3
n/2   n/4   n/4
n/2   n/3   n/6  (没有第一种大,舍去)
 
所以就判是否能 整除3 或 4
 
 
 
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <string.h>
 5 #include <stdlib.h>
 6 #include <string>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <queue>
11 #include <algorithm>
12 #include <sstream>
13 #include <stack>
14 using namespace std;
15 #define rep(i,a,n) for (int i=a;i<n;i++)
16 #define per(i,a,n) for (int i=n-1;i>=a;i--)
17 #define pb push_back
18 #define mp make_pair
19 #define all(x) (x).begin(),(x).end()
20 #define fi first
21 #define se second
22 #define SZ(x) ((int)(x).size())
23 #define FO freopen("in.txt", "r", stdin)
24 #define lowbit(x) (x&-x)
25 #define mem(a,b) memset(a, b, sizeof(a))
26 typedef vector<int> VI;
27 typedef long long ll;
28 typedef pair<int,int> PII;
29 const ll mod=1000000007;
30 const int inf = 0x3f3f3f3f;
31 ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
32 ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
33 //head
34 
35 int _, n;
36 int main() {
37     for(scanf("%d", &_);_;_--) {
38         scanf("%d", &n);
39         if(n%3 == 0) printf("%lld
", 1ll * n * n * n / 27);
40         else if(n%4 == 0) printf("%lld
", 1ll * n * n * n / 32);
41         else puts("-1");
42     }
43 }

 

 
 

以上是关于HDU6298 Maximum Multiple (多校第一场1001)的主要内容,如果未能解决你的问题,请参考以下文章

HDU6298 Maximum Multiple (多校第一场1001)

hdu 6298 Maximum Multiple(规律)

HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple

HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple

杭电2018多校第一场(2018 Multi-University Training Contest 1) 1001.Maximum Multiple (HDU6298)-数学思维题(脑子是个好东西,

hdu 6298