Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y+zn=x+y+z, x∣nx∣n, y∣ny∣n, z∣nz∣n and xyzxyz is maximum.

Input

There are multiple test cases. The first line of input contains an integer TT (1≤T≤1061≤T≤106), indicating the number of test cases. For each test case:
The first line contains an integer nn (1≤n≤1061≤n≤106).

Output

For each test case, output an integer denoting the maximum xyzxyz. If there no such integers, output −1−1 instead.

Sample Input

3
1
2
3

Sample Output

-1
-1
1

只有因子中有4或者有3才能被拆成 X+Y+Z=N,然后打了表验证。

最后wa了好几次,是因为int和int计算之后还是int就算赋值给long long .

打表代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int n;
for (int n = 1; n <= 100; n++)
{
int maxt = -1;
int a, b, c;
for (int x = 1; x <= n; x++)
{
for (int y = 1; y <= n - x; y++)
{
int z = n - x - y;
if (z && n % x == 0 && n % y == 0 && n % z == 0)
{
if (maxt < x * y * z)
{
a = x;
b = y;
c = z;
}
maxt = max(maxt, x * y * z);
}
}
}
printf("%d:%5d %d %d %d\n", n, maxt, a, b, c);
if (n % 12 == 0)
printf("\n");
}
}
return 0;
}

AC

#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
long long n,x,y,z;
long long sum;
scanf("%d", &T);
while (T--)
{
scanf("%lld", &n);
if ((n % 3) == 0)
{
x = y = z = n / 3;
sum = x * y * z;
if (x + y + z == n)
printf("%lld\n", sum);
else
puts("-1");
}
else if ((n % 4) == 0)
{
x = y = n / 4, z = n / 2;
sum = x * y * z;
if (x + y + z == n)
printf("%lld\n", sum);
else
puts("-1");
}
else
puts("-1");
}
}

数学--数论-- HDU6298 Maximum Multiple 打表找规律的更多相关文章

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

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

  2. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

  3. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  4. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  5. [国家集训队]整数的lqp拆分 数学推导 打表找规律

    题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...

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

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

  7. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  8. OpenJ_POJ C16B Robot Game 打表找规律

    Robot Game 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/B Description Sgeoghy has addi ...

  9. 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律

    转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...

随机推荐

  1. 微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

    这里主要用到了swiper组件和三目运算,直接上代码, 样式只有三个class,简单粗暴,懒的小伙伴们可以直接拿来用,喜欢的点个支持 <view> <view class=" ...

  2. 关于json语句的相关用法

    json语句: JSON 值可以是: 数字(整数或浮点数)字符串(在双引号中)逻辑值(true 或 false)数组(在中括号中)对象(在大括号中)null 对于json的的对象数组:var site ...

  3. zendframework3

    1.开发时关闭cache,正式上线后打开cache application config file (config/application.config.php),  disable this cac ...

  4. Linux服务器架设篇,DNS服务器(二),cache-only DNS服务器的搭建

    一.理论基础 什么是cache-only服务器?即不具备自己正反解Zone的能力,仅进行缓存或转发的DNS服务器.其实它也称不上是DNS服务器.但是也是一个必备的知识点. 这种服务器只有缓存搜索结果的 ...

  5. javascript 入门 之select2选择本地数据

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta lan ...

  6. MODIS系列之NDVI(MOD13Q1)二:modis数据相关信息

    1.MODIS数据的特点 (1)全球免费:NASA对MODIS数据实行全球免费接收的政策(TERRA卫星除MODIS外的其他传感器获取的数据均采取公开有偿接收和有偿使用的政策),这样的数据接收和使用政 ...

  7. SpringMVC框架详细教程(四)_使用maven导入各个版本的Spring依赖包

    使用maven导入Spring依赖包 上一节讲了如何向动态Web项目添加下载的Spring依赖包,作为补充下面列出了如何使用 maven 导入Spring的依赖包,可以选择需要的导入(推荐)或者全部导 ...

  8. sprint3总结 && sprint4计划

    sprint3总结 在一周时间里,逻辑部分顺利的将数据库,查词,UI部分连接到一起.并且各部分也针对新的要求做出了一些修改,目前数据库和查词alpha版已经完成,UI部分还需要一些美化,逻辑部分也还需 ...

  9. 【高频 Redis 面试题】Redis 事务是否具备原子性?

    一.Redis 事务的实现原理 一个事务从开始到结束通常会经历以下三个阶段: 1.事务开始 客户端发送 MULTI 命令,服务器执行 MULTI 命令逻辑. 服务器会在客户端状态(redisClien ...

  10. vue原生表格怎样实现动态列及表格数据下载

    最近项目经常用到带有合并效果以及动态列的表格,而翻阅iview和element-ui官网没有找到合适的(也有可能自己的水平有限,不会改写),所以只好自己用原生表格写了一个,具体效果如下: 这个表格右侧 ...