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 ...
随机推荐
- web Servise(服务)
服务层:对项目的业务层(业务层调用数据层)的一个包装成对外的服务,是的UI展示可以从单一的WEB扩展为移动端可WINDFROM端等,这叫做面向服务的编程思想. 发布:和网站发布也是一样的. //web ...
- layer使用总结一配置
导入layer.js文件即可,必须先导入jquery.js文件,因为layer是基于jquery 版本匹配,在此记录一下,layer使用1.8下载时是2.3的版本,对应的jquery使用1.8.3版本 ...
- opennebula 安装指定参数
[root@opennebula opennebula-]# ./install.sh -u oneadmin -g oneadmin -k -d /home/oneadmin/ -u 指定用户-g ...
- 2-chrome无法添加扩展程序
1.更多工具->拓展程序->打开开发者模式->重启浏览器 2.将拓展程序拖入,确认安装
- Qt5信号和槽机制
信号槽是 Qt 框架引以为豪的机制之一.熟练使用和理解信号槽,能够设计出解耦的非常漂亮的程序,有利于增强我们的技术设计能力. 所谓信号槽,实际就是观察者模式.当某个事件发生之后,比如,按钮检测到自己被 ...
- win32多线程 (一) 线程创建与结束等待
#include "stdafx.h"#include <Windows.h>#include <iostream> using namespace std ...
- Python3 使用requests库读取本地保存的cookie文件实现免登录访问
1. 读取selenium模块保存的本地cookie文件来访问知乎 读取http://www.cnblogs.com/strivepy/p/9233389.html保存的本地cookie来访问知乎的 ...
- 《the art of software testing》第六章
更高级别的测试 模块测试的目的是发现程序模块与其接口规格说明之间的不一致 功能测试的目的是为了证明程序未能符合其外部规格说明 系统测试目的是为了证明软件产品与其初始目标不一致 功能测试,作者从三个方面 ...
- [GO]指针和函数配合的值传递
package main import "fmt" func swap(a, b int) { a, b = b, a fmt.Printf("a = %d, b = % ...
- javascript总结18:javascript DOM简介
1 HTML DOM 使 JavaScript 有能力对 HTML 事件做出反应.在事件发生时,执行JavaScript 方法,做出交互. 2 格式: onclick=JavaScript脚本 3 H ...