一、题目

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. Loadrunner Analyze

    Analysis 对controller运行的结果进行分析 1.首先必须明确:光靠Analysis是不行的,只要能通过Analysis分析出部分问题就已经很不错了, 善于利用它才是最关键的. 2.如何 ...

  2. C++——STL之vector, list, deque容器对比与常用函数

    STL 三种顺序容器的特性对比: vector 可变数组,内存空间是连续的,容量不会进行缩减.支持高效随机存取,即支持[]和at()操作.尾部插入删除效率高,其他位置插删效率较低: list 双向链表 ...

  3. php const static define 基本用法和区别

    const  定义一些在运行时不能被改变的数值.一旦值被改变,则会发生错误. 特性 只能用类名访问.不需要用 $  符号 <?php class test{ const pi=123.12321 ...

  4. DEDE 5.7中各函数所在的文件和位置

    /include/taglib/tag.lib.php 2 //function GetTags()/include/payment/yeepay.php 415 function log_resul ...

  5. Django框架 之 中间件

    Django框架 之 中间件 浏览目录 中间件介绍 自定义中间件 中间件的执行流程 中间件版登录验证 一.中间件介绍 官方的说法:中间件是一个用来处理Django的请求和响应的框架级别的钩子.它是一个 ...

  6. hdu 4768 Flyer (异或操作的应用)

    2013年长春网络赛1010题 继巴斯博弈(30分钟)签到后,有一道必过题(一眼即有思路). 思路老早就有(40分钟):倒是直到3小时后才被A掉.期间各种换代码姿态! 共享思路: unlucky st ...

  7. C++读取txt文件(VS)

    最常用的方法?https://www.cnblogs.com/nkzhangcheng/p/7722568.html https://blog.csdn.net/a125930123/article/ ...

  8. Machine Learning and Data Mining(机器学习与数据挖掘)

    Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...

  9. Python - selenium_WebDriver 页面元素操作

    代码是自己写了 python WebDriver  页面操作的常用方法. from selenium import webdriver import time driver = webdriver.F ...

  10. wc.exe C++实现

    目录 Github项目地址 PSP表格 解题思路 设计实现过程 测试运行 项目小结 Github项目地址 wc-project PSP表格 PSP2.1 Personal Software Proce ...