美文网首页
1001. Maximum Multiple

1001. Maximum Multiple

作者: laochonger | 来源:发表于2018-07-24 09:29 被阅读0次

1001. Maximum Multiple

  • Time limit: 2 seconds
  • Memory limit: 32 megabytes
    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≤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

题意:把给的一个n分解为三个数,这三个数必须分别被n整除,输出这三个书的最大乘积,若无法找出,则输出-1
思路:1 = (1/2+1/3+1/6 =) 1/4+1/4+1/2 = 1/3+1/3+1/3
也就是说,这个数一定是3或者4的倍数,需要注意的是,题目中给的范围是10^6三次方后会超出范围,所以用lld

so:

#include <cstdio>

int main() {
  int T;
  scanf("%d", &T);
  for (int cas = 1; cas <= T; ++cas) {
    int n;
    scanf("%d", &n);
    if (n % 3 == 0) printf("%lld\n", 1ll * n * n * n / 27);
    else if (n % 4 == 0) printf("%lld\n", 1ll * n * n * n / 32);
    else puts("-1");
  }
  return 0;
}

相关文章

网友评论

      本文标题:1001. Maximum Multiple

      本文链接:https://www.haomeiwen.com/subject/twfemftx.html