嗯,暑假参加了两种多校,一个是牛客网的,一个是航电的,一共20场,我的目标是20场有10场,打进铜牌区域,就算合格了。这一场是第一场打进铜牌区,感谢我队友贡献了3道题,我贡献了一道题,4题成功打进铜牌区。当然了网络赛人多,水分也大。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6298
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,n满足 n = x + y + z ,并且x,y,z能都能整除n。求出xyz的最大值。当然这些数字都是正整数。
题解:我们先推几组样例
1没有办法分,所以不行
2也没有办法,所以不行
3可以被分为1,1,1,并且 3%1 == 0,所以可以
4可以被分为1,1,2,并且 4%1 == 0,4%2 == 0 ,所以可以。
5可以被分为1,1,3,或者 1,2,2,没办法整除,所以不行
6可以被分为2,2,2或者1,2,3。后者不行,前者可以。
7可以被分为1,1,5或者1,2,4,或者2,2,3,或者,1,3 ,3,没办法整除。
8可以被分为,2,2,4,可以整除。
……
只有能被3或4整除的,可以。
推规律=-=
或者我们可以把这个问题看成,把一个东西分成三份
就有
那么只有这三种情况。
若是,2,3,6 则n要满足条件为,能整出6
若是,2,2,2,则要满足条件为,能整除3,
若是,2,4,4,则n要满足条件,能整除4.
对于一个数则有 n = n/2 + n/3 + n/6 = n/3 + n/3 + n/3 = n/2 + n/4 + n/4
则有 xyz = n*n*n/36 = n*n*n / 27 = n*n*n/32
我们要满足xyz最大。所以。嗯
整除3或者4满足条件。
代码如下
#include<bits/stdc++.h>
#define ll long long
#define exp 1e-8
#define mst(a,k) memset(a,k,sizeof(a))
#define pi acos(-1.0)
using namespace std;
ll n;
int main()
{
ll t, ans;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
if(n%3==0||n%4==0)
{
if(n%3==0) {
n/=3;
ans = n * n * n;
printf("%lld\n",ans);
}
else {
n /= 4;
ans = n * n * (n * 2);
printf("%lld\n", ans);
}
}
else {
printf("-1\n");
}
}
}