A - Maximum Multiple

题意:给出一个n 找x, y, z 使得$n = x + y +z$ 并且 $n \equiv 0 \pmod x, n \equiv 0 \pmod y, n \equiv 0 \pmod z$ 并且使得 $x \cdot y \cdot z$ 最大

思路:设$a = \frac{n}{x}, b = \frac{n}{y}, c = \frac{n}{z}$ 那么 $\frac{1}{a} + \frac{1}{b} + \frac{1}{c} = 1$ 那么我们考虑去凑 a, b, c

两种方案  ${3, 3, 3}$  或者 ${2, 4, 4}$ 取max

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 
 7 ll n;
 8 
 9 int main()
10 {
11     int t;
12     scanf("%d", &t);
13     while(t--)
14     {
15         scanf("%lld", &n);
16         if(n % 3 == 0)
17         {
18             ll ans = n / 3;
19             ans *= n / 3;
20             ans *= n / 3;
21             printf("%lld\n", ans);
22         }
23         else if(n % 4 == 0)
24         {
25             ll ans = n / 2;
26             ans *= n / 4;
27             ans *= n / 4;
28             printf("%lld\n", ans);
29         }
30         else
31         {
32             puts("-1");
33         }
34     }
35     return 0;
36 }
View Code

相关文章: