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");
}
}

数学--数论--HDU-2698 Maximum Multiple(规律)的更多相关文章

  1. hdu 6298 Maximum Multiple (简单数论)

    Maximum Multiple Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu 6298 Maximum Multiple(规律)

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

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

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

  4. 数学--数论--HDU 2582 F(N) 暴力打表找规律

    This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...

  5. 数学--数论--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 ...

  6. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  7. 数学--数论--HDU 2197 本原串 (推规律)

    由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串? 答案mod2008. 例如,100100不是本原串,因为他是由两个 ...

  8. 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂

    Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...

  9. 数学--数论--HDU 6063 RXD and math (跟莫比乌斯没有半毛钱关系的打表)

    RXD is a good mathematician. One day he wants to calculate: output the answer module 109+7. p1,p2,p3 ...

  10. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

随机推荐

  1. python 程序双击执行的小技巧

    文章更新于:2020-04-03 按照惯例,需要的文件附上链接放在文首. 文件名:ICOFX图标制作软件.7z 文件大小:40.2 MB 下载链接:https://www.lanzous.com/ia ...

  2. 一天学一个Linux命令:第一天 ls

    文章更新于:2020-03-02 注:本文参照 man ls 手册,并给出使用样例. 文章目录 一.命令之`ls` 1.名字及介绍 2.语法格式 3.输出内容示例 4.参数 二.命令实践 1.`ls ...

  3. 10.1 io流--ASCII码表

    day2.8中提到 /* * +: * 做加法运算 * * 字符参与加法运算,其实是拿字符在计算机中存储的数据值来参与运算的 * 'A' 65(B 66...) * 'a' 97(b 98...) * ...

  4. "按钮"组件:<h-button> —— 快应用组件库H-UI

     <import name="h-button" src="../Common/ui/h-ui/basic/c_button"></impo ...

  5. "文字链接"组件:<h-link> —— 快应用组件库H-UI

     <import name="h-link" src="../Common/ui/h-ui/basic/c_link"></import&g ...

  6. JS入门系列(2)-原型-实例属性

    下面的例子中,在构造器内部定义了like,然后再原型上也定义了like.通过下面的测试表明: 在构造器内部创建的实例方法会阻挡原型上定义的同名方法 初始化操作的优先级如下: 首先,通过原型给对象实例添 ...

  7. lr 遇到的问题

    1.Abnormal termination, caused by mdrv process termination 解决方法:修改LR中的D:\Program Files\Mercury\LoadR ...

  8. ln -s 软链接命令

    所有对软链接link_name的操作都是对目录或文件dir_file的操作 ln -s [dir_file] [link_name]

  9. Python-元组tuple、列表list、字典dict

    1.元组tuple(1)元组是有序列表,有不可见的下标,下标从0开始(2)元组的数据是相对固定的,数据不能增删改,他的一个重要用途是保存固定的.安全要求高的数据(3)元组用小括号()括起来,空元组定义 ...

  10. Daily Scrum 1/18/2016

    Yandong & Zhaoyang: Prepare bug bash slides for Beta release; Dong & Fuchen:Prepare demo for ...