HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple
Posted qq965921539
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 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).
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
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 }
以上是关于HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple的主要内容,如果未能解决你的问题,请参考以下文章
HDU6301-2018ACM暑假多校联合训练1004-Distinct Values
HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories
暑假N天乐比赛篇 —— 2019杭电暑期多校训练营(第五场)