2018HDU多校联赛第一场Maximum Multiple

我就是我 2022-05-19 10:04 364阅读 0赞

题目衔接:http://acm.hdu.edu.cn/showproblem.php?pid=6298

Maximum Multiple

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

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

Source

2018 Multi-University Training Contest 1

题目大意:给你一个数,问你能不能找到3个数x,y,z,使得x+y+z=n且使得n能整除以x,n能整除以y,n能整除以z,如果有找出最大的x*y*z

思路:先打表,可以看出规律:能整除以3的都是n*n*n,能整除以4的都是n*n*(n*2);所以这就是规律

代码:

  1. #include<map>
  2. #include<stack>
  3. #include<queue>
  4. #include<cstdio>
  5. #include<string>
  6. #include<cstring>
  7. #include<cstdlib>
  8. #include<iostream>
  9. #include<algorithm>
  10. using namespace std;
  11. #define maxn 100
  12. #define ll long long
  13. int main()
  14. {
  15. int test;
  16. scanf("%d",&test);
  17. while(test--)
  18. {
  19. ll n;
  20. ll ans=-1;
  21. scanf("%lld",&n);
  22. if(n%3==0)
  23. {
  24. n/=3;
  25. ans=n*n*n;
  26. }
  27. else if(n%4==0)
  28. {
  29. n/=4;
  30. ans=n*n*(n*2);
  31. }
  32. else
  33. ans=-1;
  34. printf("%lld\n",ans);
  35. }
  36. return 0;
  37. }

发表评论

表情:
评论列表 (有 0 条评论,364人围观)

还没有评论,来说两句吧...

相关阅读