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

  1. 3
  2. 1
  3. 2
  4. 3

Sample Output

  1. -1
  2. -1
  3. 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一组;

参考代码为:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. int main()
  5. {
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. LL T,n,x,y,z,sum;
  9. cin>>T;
  10. while(T--)
  11. {
  12. cin>>n;
  13. if((n%3)==0)
  14. {
  15. x=y=z=n/3;
  16. sum=x*y*z;
  17. if(x+y+z==n) cout<<sum<<endl;
  18. else cout<<-1<<endl;
  19. }
  20. else if((n%4)==0)
  21. {
  22. x=y=n/4,z=n/2;
  23. sum=x*y*z;
  24. if(x+y+z==n) cout<<sum<<endl;
  25. else cout<<-1<<endl;
  26. }
  27. else cout<<-1<<endl;
  28. }
  29. return 0;
  30. }

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. @resource和@autowired的区别是什么-CSDN论坛-CSDN.NET-中国最大的IT技术社区 - Google Chrome

    @Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了.@Resource有两个属性是比较重要的,分 ...

  2. 致和我一样迷茫的Java程序员们

    缘起 从事近7年Java开发之后,在2019年这个寒冷的冬天里,我终于迎来了人生中的第一次裁员. 啊,30岁之后的裁员真让人焦虑. 按照以往惯例,在面试心仪的公司之前,需要先面试一些不那么心仪的公司热 ...

  3. java编程思想第四版第九章习题

    第三题 package net.mindview.interfaces; abstract class Base{ public Base(){ print(); } abstract void pr ...

  4. c#控制台玩飞行棋游戏

    using System; namespace Game{ class Program { //用静态字段模拟全局变量 public static int[] Maps = new int[100]; ...

  5. [springboot 开发单体web shop] 7. 多种形式提供商品列表

    上文回顾 上节 我们实现了仿jd的轮播广告以及商品分类的功能,并且讲解了不同的注入方式,本节我们将继续实现我们的电商主业务,商品信息的展示. 需求分析 首先,在我们开始本节编码之前,我们先来分析一下都 ...

  6. sqlcipher的php扩展运行在fast-cgi:php-fpm下工作不正常

    今天发现了这样的问题,php-fpm运行sqlcipher时,有些数据库工作正常,有些却不正常. 不正常的,都在日志上报错,也就是php处理异常了. 这个报错发生在执行sql语句时,通常就是sqlci ...

  7. pod删除主要流程源码解析

    本文以v1.12版本进行分析 当一个pod删除时,client端向apiserver发送请求,apiserver将pod的deletionTimestamp打上时间.kubelet watch到该事件 ...

  8. 使用class关键字创建类组件、props参数

    import React,{Component} from 'react' import {render} from 'react-dom' // 使用class创建组件 class Movie ex ...

  9. python:利用celery分布任务

    Celery是一个功能完备即插即用的任务队列.它使得我们不需要考虑复杂的问题,使用非常简单.celery看起来似乎很庞大.celery适用异步处理问题,当发送邮件.或者文件上传, 图像处理等等一些比较 ...

  10. Openlayers Projection导致经纬度颠倒问题

    问题: openlayers3调用TileWMS接口,实现Openlayers加载Geoserver转发的ArcGIS切片时,web墨卡托(wkid3857)没有问题,但是WGS84(wkid4326 ...