HDU 6298 Maximum Multiple(找规律)

题目链接:Maximum Multiple

题意

给定一个整数 n n ,找到三个整数 x,y,z,要求满足 x+y+z=n x + y + z = n x,y,z x , y , z 都能整除 n n ,要使得 xyz 的值最大,求 xyz x y z 的最大值。

输入

第一行为一个整数 T (1T106) T   ( 1 ≤ T ≤ 10 6 ) ,表示数据组数,接下去 T T 行每行一个整数 n (1n106)

输出

如果存在满足条件的 x,y,z x , y , z 的值,输出其中 xyz x y z 的最大值,如果不存在满足条件的值,则输出 1 − 1

样例

输入
3
1
2
3
输出
-1
-1
1
题解

暴力打表找规律,可以发现如果 n n 3 的倍数,那么 x,y,z x , y , z 的值一定都是 n3 n 3 ,如果 n n 4 的倍数,那么 x,y,z x , y , z 其中一个数是 n2 n 2 ,另外两个数是 n4 n 4 ,其他情况都输出 1 − 1

过题代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define LL long long
int T;
LL n, a, b, c, ans;

int main() {
    #ifdef Dmaxiya
    freopen("test.txt", "r", stdin);
    #endif // Dmaxiya
    ios::sync_with_stdio(false);

    scanf("%d", &T);
    while(T--) {
        scanf("%I64d", &n);
        a = b = c = -1;
        if(n % 3 == 0) {
            a = b = c = n / 3;
        } else if(n % 4 == 0) {
            a = b = n / 4;
            c = a * 2;
        }
        if(a == -1) {
            printf("-1\n");
        } else {
            printf("%I64d\n", a * b * c);
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值