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;
}

2018HDU多校训练一 A - Maximum Multiple的更多相关文章

  1. 2018HDU多校训练-3-Problem G. Interstellar Travel

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325                                   Interstellar Tra ...

  2. 2018HDU多校训练一 K - Time Zone

    Chiaki often participates in international competitive programming contests. The time zone becomes a ...

  3. 2018HDU多校训练一 D Distinct Values

    hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...

  4. 2018HDU多校训练一 C -Triangle Partition

    Chiaki has 3n3n points p1,p2,-,p3np1,p2,-,p3n. It is guaranteed that no three points are collinear.  ...

  5. 2018HDU多校训练-3-Problem M. Walking Plan

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan  Problem Description There are n inte ...

  6. 2018HDU多校训练-3-Problem F. Grab The Tree

    Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2 ...

  7. 2018HDU多校训练-3-Problem D. Euler Function

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...

  8. HDU 多校对抗赛 A Maximum Multiple

    Maximum Multiple Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. HDU6298 Maximum Multiple (多校第一场1001)

    Maximum Multiple Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. iOS蓝牙--CoreBluetooth基本使用

    蓝牙使用步骤: 1. 扫描外设 2. 连接外设 3. 连上外设后,获取指定外设的服务 4. 获取服务后,遍历服务的特征,得到可读,可写等特征,然后与中心管理者进行数据交互 附上代码 一:导入框架 #i ...

  2. Linux常用命令复习

    1> 查看文件信息:ls ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令. Linux文件或者目录名称最长可以有265个字符,“.”代 ...

  3. 结合参数接收响应转换原理讲解SpringBoot常用注解

    一.常用注解回顾 1.1 @RequestBody与@ResponseBody //注意并不要求@RequestBody与@ResponseBody成对使用. public @ResponseBody ...

  4. PHP 从另一个角度来分析 Laravel 框架的依赖注入功能

    从根本上说,依赖注入不是让对象创建一个依赖关系,也不是让工厂对象去创建对象,而是将所需的依赖变成一个外部对象,使之成为一个"某些人的问题” 你为"某些人的问题”注入了类的依赖关系. ...

  5. ESP8266 智能配网 断电重连

    ESP8266 智能配网 断电重连 #include <ESP8266WiFi.h> bool autoConfig() { WiFi.begin(); for (int i = 0; i ...

  6. 力扣(LeetCode)单值二叉树 个人题解

    如果二叉树每个节点都具有相同的值,那么该二叉树就是单值二叉树. 只有给定的树是单值二叉树时,才返回 true:否则返回 false. 示例 1: 输入:[1,1,1,1,1,null,1] 输出:tr ...

  7. CSS RESET —— 浏览器样式重置

    CSS Reset 1. CSS Reset为什么存在? 只要您的客户存在使用不同浏览器(ie,firefox,chrome等)的可能,那你就不得不从完美的理想状态回到现实,因为不同核心的浏览器对CS ...

  8. ubuntu server 1604 设置笔记本盒盖 不操作

    sudo vim /etc/systemd/logind.conf   //打开配置文件 找到 #HandleLidSwitch=suspend  改为 HandleLidSwitch=ignore  ...

  9. PostGIS 递归方法

    在Oracle数据库中,有可以实现递归的函数 select * from table_name start with [condition1] connect by [condition2] 最近发现 ...

  10. GeoServer 查询sql视图

    说明: 最近项目中遇到一个需求,需要统计管网的长度,但管网数据量非常大,前端用openlayers接口统计直接就奔溃了. 后尝试使用调后台接口查数据库的方式,虽然可行但是又要多一层与后台交互的工作. ...