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

题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大
从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求
被3整除的最大值为n^3/3^3
被4整除的最大值为n^3/(2*4*4)
Problem Description
Given an integer  n, Chiaki would like to find three positive integers xy and z such that: n=x+y+zxnynzn 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

 

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     ios::sync_with_stdio(false);
 8     int t;
 9     cin >> t;
10     while (t--)
11     {
12         long long n;
13         cin >> n;
14         if (n % 3 == 0)
15             cout << (n / 3)*(n / 3)*(n / 3) << endl;
16         else if (n % 4 == 0)
17             cout << (n / 2)*(n / 4)*(n / 4) << endl;
18         else
19             cout << "-1" << endl;
20     }
21     return 0;
22 }

 

转载于:https://www.cnblogs.com/qq965921539/p/9360692.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值