一、题目

Given an integer $n$, Chiaki would like to find three positive integers $x$, $y$ and $z$ such that: $n=x+y+z$, $x\mid n$, $y \mid n$, $z \mid n$ and $xyz$ is maximum. 

InputThere are multiple test cases. The first line of input contains an integer $T$ ($1 \le T \le 10^6$), indicating the number of test cases. For each test case: 
The first line contains an integer $n$ ($1 \le n \le 10^{6}$). 
OutputFor 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

二、分析

需要先按照题意分析(20项即可),然后发现能输出答案的都是3或者4的倍数,那么x,y,z的结构就是1+1+1和1+1+2的模式,如果出现3和4的公倍数,为了能保证xyz的更大值,优先考虑1+1+1的结构。

三、代码

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL; LL Max(const LL a, const LL b)
{
return a>b?a:b;
}
/*** 找规律代码 ***/
void solve(int N)
{
LL ans = -1;
for(int i = 1; i < N; i++)
{
for(int j = 1; j < N; j++)
{
for(int k = 1; k < N; k++)
{
if(N%i == 0 && N%j == 0 && N%k == 0 && N == i+j+k)
{
ans = Max(i*j*k, ans);
}
}
}
}
cout << ans <<endl; } int main()
{
int T, N;
LL ans;
scanf("%d", &T);
while(T--)
{
scanf("%d", &N);
if(N%3==0)
{
ans = (LL)(N/3)*(N/3)*(N/3);
printf("%I64d\n", ans);
}
else if(N%4==0)
{
ans = (LL)(N/4)*(N/4)*(N/2);
printf("%I64d\n", ans);
}
else
printf("-1\n");
}
return 0;
}

  

HDU_6298 Maximum Multiple 【找规律】的更多相关文章

  1. hdu 6298 Maximum Multiple(规律)

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

  2. 数学--数论--HDU-2698 Maximum Multiple(规律)

    Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...

  3. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  4. 2017年icpc西安网络赛 Maximum Flow (找规律+数位dp)

    题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n- ...

  5. HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)

    Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

  7. 找规律 ZOJ3498 Javabeans

    Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...

  8. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  9. HDU 4910 Problem about GCD 找规律+大素数判断+分解因子

    Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. boost 时间与日期处理

    博客转载自: 类 特点 缺点 说明 timer 计时基类 不适合大跨度时间 适用大部分的普通计时 progress_timer 继承自timer 可以自动写入流中 只精确到0.01s 如果需要更精确, ...

  2. swing中的分层

    swing中的分层 摘自:https://blog.csdn.net/levelmini/article/details/26692205 2014年05月23日 12:42:56 阅读数:1244 ...

  3. BBS后台发送邮件&修改文章

    一:Django发送邮件 在setting中配置 # EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST ...

  4. 关于 Azure 安全性的 10 点提示

    讨论云服务时,安全性是一个关键领域.实际上,Windows Azure 基础结构实施大量的技术和流程来保护环境.此页介绍 Microsoft 的全球基础服务如何运行基础结构以及它们实施的安全措施. 从 ...

  5. _AppStart.cshtml 和 _PageStart.cshtml的妙用

    Customizing Site-Wide Behavior for ASP.NET Web Pages (Razor) Sites By Tom FitzMacken|February 17, 20 ...

  6. wpf附加属性理解

    WPF附加属性 http://www.cnblogs.com/tianyou/archive/2012/12/27/2835670.html WPF属性(二)附加属性 http://blog.csdn ...

  7. linux select 返回值

    IBM AIX上 select返回值的 man if  a connect-based socket is specified in the readlist parameter and the co ...

  8. 微信运动数据抓取(PHP)

    “微信运动”能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据.url类似于:http://hw.weixin.qq.com/steprank/step/personal?openid= ...

  9. ecliplse的下载安装

    ecliplse的官方下载地址是: https://www.eclipse.org/downloads/packages/ 进去的速度可能比较慢,请耐心等待,进去之后的页面如下,为了便于理解下面的是我 ...

  10. [AGC006] D - Median Pyramid Hard 二分

    Description ​ 现在有一个NN层的方块金字塔,从最顶层到最底层分别标号为1...N1...N. ​ 第ii层恰好有2i−12i−1个方块,且每一层的中心都是对齐的. 这是一个N=4N=4的 ...