HDU_6298 Maximum Multiple 【找规律】
一、题目
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 【找规律】的更多相关文章
- hdu 6298 Maximum Multiple(规律)
hdu6298 Maximum Multiple 题目传送门 题意: 给你一个整数n,从中找出可以被n整除的三个数x,y,z: 要求x+y+z=n,且x*y*z最大. 思路: 开始一看T到1e6,n也 ...
- 数学--数论--HDU-2698 Maximum Multiple(规律)
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...
- Codeforces 870C Maximum splitting (贪心+找规律)
<题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...
- 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- ...
- HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- 找规律 ZOJ3498 Javabeans
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 4910 Problem about GCD 找规律+大素数判断+分解因子
Problem about GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- Angular25 组件的生命周期钩子
1 生命周期钩子概述 组件共有9个生命周期钩子 1.1 生命周期的执行顺序 技巧01:测试时父组件传递对子组件的输入属性进行初始化操作 import { Component, Input, Simpl ...
- opennebula 安装指定参数
[root@opennebula opennebula-]# ./install.sh -u oneadmin -g oneadmin -k -d /home/oneadmin/ -u 指定用户-g ...
- Ubuntu 源使用帮助
地址 https://mirrors.ustc.edu.cn/ubuntu/ 说明 Ubuntu 软件源 收录架构 AMD64 (x86_64), Intel x86 其他架构请参考 Ubuntu P ...
- YDNJS(上卷):this 的绑定对象
函数中的 this 是在调用时被绑定的,this 指向谁完全取决于函数的调用位置. 确定 this 的绑定对象的方式有 4 种. 默认绑定 默认绑定就是将函数中的 this 绑定给了全局对象 wind ...
- JPA注解解析
最近学习hibernate注解形式配置POJO类,将注解的解析记下来,以备以后使用. 例1. @Entity@Table(name="user") public class Fl ...
- 编写高质量代码改善C#程序的157个建议——建议43:让接口中的泛型参数支持协变
建议43:让接口中的泛型参数支持协变 除了上一建议中提到的使用泛型参数兼容接口不可变性外,还有一种办法是为接口中的泛型声明加上out关键字来支持协变,如下所示: interface ISalary&l ...
- Git教程--廖雪峰
Git简介 1.Git是目前世界上最先进的分布式版本控制系统(没有之一) 2.集中式和分布式版本控制系统有什么区别呢? 区别在于历史版本维护的位置:Git本地仓库包含代码库还有历史库,在本地 ...
- MongoDB整理笔记の索引
MongoDB 提供了多样性的索引支持,索引信息被保存在system.indexes 中,且默认总是为_id创建索引,它的索引使用基本和MySQL 等关系型数据库一样.其实可以这样说说,索引是凌驾于数 ...
- C#导出Excel-利用特性自定义数据
网上C#导出Excel的方法有很多.但用来用去感觉不够自动化.于是花了点时间,利用特性做了个比较通用的导出方法.只需要根据实体类,自动导出想要的数据 1.在NuGet上安装Aspose.Cells或 ...
- C# LINQ(8)
回顾之前的代码都是LINQ自行推断类型.其实LINQ在查询的结束是可以动态创建类型. , , , , , , , , , , }; var list = from num in intArray &a ...