HDU - 6298 Maximum Multiple

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 TT (1≤T≤10^6), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤10^6).

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

总结:又是一个规律题,起先对x|n,表示疑问,不知道是什么意思。WA了几次后就彻底懵了。。。所以知识量,刷题里昂还是相当重要的。

分析:本题要求三个数x,y,z,使得n= x+y+z,且x,y,z均为n的因数。且要求xyz的最大值。

将你看做一个整体那么就有

1 = 1/4+1/4+1/2;

扫描二维码关注公众号,回复: 2540125 查看本文章

1= 1/3+1/3+1/3;

1 = 1/2+1/3+1/6;

因为要求xyz的最大值,且x,y,z可以被n整除。所以 只要n可以整除3或整除4即有满足上述条件的最大值。

附代码:

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
	long long  n,T;
	while (scanf("%lld",&T)!=EOF)
	{
		for (int i = 0; i < T; i++)
		{
			scanf("%lld", &n);
			if (n % 3 == 0)
			{
				printf("%lld\n", (n / 3)*(n / 3)*(n / 3));
			}
			else if (n % 4 == 0)
			{
				printf("%lld\n", (n / 4)*(n / 4)*(n / 2));
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	return 0;
}

注意一点cin,cout输出较慢,在大的数据面前还是用scanf和printf。

猜你喜欢

转载自blog.csdn.net/fighting_yifeng/article/details/81268082
今日推荐