Maximum Multiple

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 494    Accepted Submission(s): 215

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≤106), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤106).
 
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
 
题意:

找到三个正整数x,y和z,使得:n = x + y + z,x /n,y / n,z / n和xyz是最大的。

题解:

x+y+z=n

设r=n/x,s=n/y,t=n/z

所以 1/r+1/s+1/t=1;

设 r<=s<=t;

所以r<=3

r=2     1/s+1/t=1/2;   s=t=4  | s=3 ,t=6

r=3      s=t=3;

如果3/n的话 就分成 n/3,n/3,n/3;

n/2,n/4,n/4;

n/2,n/3,n/6; //这种的乘积小于其余的,舍弃

n可以被3整除的话就分成n/3,n/3,n/3的情况
n可以被4整除的情况就分成n/2,n/4,n/4的情况
 

代码如下

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
int T;
scanf("%d",&T);
while(T--){
ll n;
scanf("%lld",&n);
if(n%==){
ll x=n/;
ll ans=x*x*x;
printf("%lld\n",ans);
}
else if (n%==){
ll x=n/;
ll ans=x*n/*n/;
printf("%lld\n",ans);
}else{
printf("-1\n");
}
}
return ;
}

HDU 多校对抗赛 A Maximum Multiple的更多相关文章

  1. HDU 多校对抗赛 B Balanced Sequence

    Balanced Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. HDU 多校对抗赛第二场 1004 Game

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. HDU 多校对抗赛第二场 1010 Swaps and Inversions

    Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. HDU 多校对抗赛 D Distinct Values

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU 多校对抗赛 C Triangle Partition

    Triangle Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Oth ...

  6. HDU 多校对抗赛 J Time Zone

    Time Zone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

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

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

  8. hdu 6298 Maximum Multiple (简单数论)

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

  9. hdu 6298 Maximum Multiple(规律)

    hdu6298 Maximum Multiple 题目传送门 题意: 给你一个整数n,从中找出可以被n整除的三个数x,y,z: 要求x+y+z=n,且x*y*z最大. 思路: 开始一看T到1e6,n也 ...

随机推荐

  1. PHP错误:Warning: preg_replace() [function.preg-replace]: Unknown modifier '[' in

    遇到一个PHP错误,错误提示是 Warning: preg_replace() [function.preg-replace]: Unknown modifier '[' in  .... , 当然了 ...

  2. PAT (Basic Level) Practice (中文)1002

    1002 写出这个数 (20 分) 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 1 ...

  3. Mysql 启动运行

    MYSQL默认端口:3306用户: root   也可自己添加用户启动数据库服务名: MYSQL (在安装的时候会设置) 在开始菜单栏->附件->右键命令提示符->以管理员身份运行: ...

  4. lua基础知识笔记

    一.lua中的数据类型 1.数值 a = 1 b = 1.2 2.字符串 c = "hello world" 3.布尔 d = true f = false 4.表(Table) ...

  5. jenkins手动安装插件

    插件下载地址: 搜索:https://plugins.jenkins.io/ 列表:https://updates.jenkins-ci.org/download/plugins/ 打开jenkins ...

  6. 修改npm全局安装模式的路径

    由于npm全局模块的存放路径及cache的路径默认是放在C盘下,这样肯定会增加C盘的负担,那么如果需要修改其存放路径应该怎么做呢? 第一步:在nodejs安装目录(也可以指定其它目录)下创建”node ...

  7. 使用testng.xml组织测试用例

    测试用例类TeseNG.java: import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.open ...

  8. Tuxedo 介绍与安装

    Tuxedo 介绍与安装(一) Tuxedo介绍                                                                             ...

  9. coia阻止事件上浮

    1.阻止事件上浮 选择默认地址li 时 选中整个div使其为默认地址 此时点击编辑按钮也会触发选中默认事件 为事件添加event.stopPropagation();阻止事件上浮 2.js给页面inp ...

  10. linux学习总结-----web前端①

    <html> <head> <title></title> <meta charset='utf-8'/> ... </head> ...