Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y+zn=x+y+z, x∣nx∣n, y∣ny∣n, z∣nz∣n and xyzxyz is maximum.

Input

There are multiple test cases. The first line of input contains an integer TT (1≤T≤1061≤T≤106), indicating the number of test cases. For each test case: 

The first line contains an integer nn (1≤n≤1061≤n≤106).

Output

For each test case, output an integer denoting the maximum xyzxyz. If there no such integers, output −1−1 instead.

Sample Input

3
1
2
3

Sample Output

-1
-1
1

题意:给你一个整数n,3个整数 x,y,z.让你求满足 n=x+y+z,x*y*z的最大值;

令 a=n/x ,b=n/y, c=n/z,  则1/a+1/b+1/c=1;且a,b,c为正整数,则a,b,c可取  3 3 3,2 4 4; 2 3 6;

2 3 6的话没有取没有3 3 3大,故这个可以省去,就剩下 3 3 3; 2 4 4;先考虑是否可以被3整除,再考虑是否可以被4整除,以为3 个数和一定能话,相等时乘积最大,都不满足输出-1,都满足输出 3 3 3一组;

参考代码为:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
LL T,n,x,y,z,sum; cin>>T;
while(T--)
{
cin>>n;
if((n%3)==0)
{
x=y=z=n/3;
sum=x*y*z;
if(x+y+z==n) cout<<sum<<endl;
else cout<<-1<<endl;
}
else if((n%4)==0)
{
x=y=n/4,z=n/2;
sum=x*y*z;
if(x+y+z==n) cout<<sum<<endl;
else cout<<-1<<endl;
}
else cout<<-1<<endl;
} return 0;
}

最新文章

  1. Ninject使用介绍
  2. ffmpeg-20160701-git-bin.7z
  3. [原]零基础学习在Android进行SDL开发系列文章
  4. 算法分析 Analysis of Algorithms -------GeekforGeeker 翻译
  5. wget的下载与安装使用
  6. BZOJ3122 随机数生成器
  7. 关于css样式的看法
  8. C#删除数组元素代码
  9. apply 与arguments的用法
  10. 《python基础教程》笔记之 条件语句和循环语句
  11. 一天一个类--ArrayList之二
  12. [HDU1210] Eddy&#39;s 洗牌问题
  13. NDK开发小记录 C++读取java层对象内容
  14. Angular使用总结 --- 模版驱动表单
  15. Spark学习之路 (一)Spark初识
  16. js:基于原生js的上啦下啦刷新功能
  17. 你真的懂redis的数据结构了吗?redis内部数据结构和外部数据结构揭秘
  18. 姿势摆好,一招学会android的布局优化!
  19. java impl
  20. OOAD和UML

热门文章

  1. Jetpack Compse 实战 —— 全新的开发体验
  2. C++中对C的扩展学习新增语法——lambda 表达式(匿名函数)
  3. PHP队列的实现详细操作步骤
  4. PhpStudy BackDoor2019 深度分析
  5. UNIX env查找技巧
  6. GitHub远程库的搭建以及使用
  7. python3 之 面向对象(类)、继承、派生和多态
  8. cenos7搭建gitlab
  9. 【2018寒假集训Day 1】【位运算】生成字符串
  10. java struts2 debug