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

最新文章

  1. php lock_sh共享锁 与 lock_ex排他锁
  2. 使用canvas实现擦玻璃效果---转载
  3. LPTHW 笨方法学python 18章
  4. ATMEL处理器自带USB CDC的Win7驱动问题
  5. PHP时间日期
  6. 利用ADSL拨号上网方式如何搭建服务器
  7. flex 4 布局样式
  8. iOS开发——实用篇Swift篇&amp;项目开发常用实用技术
  9. WTL的核心机制
  10. Google Chrome 默认非安全端口列表
  11. JS--我发现,原来你是这样的JS:面向对象编程OOP[2]--(创建你的那个对象吧)
  12. Cassandra最小化安装
  13. [math]本博客已经支持书写数学公式
  14. 查找二叉树(tree_a)
  15. 自定义滤镜 ColorMatrixFilter
  16. 朴素贝叶斯分类算法介绍及python代码实现案例
  17. npm下载指定版本的插件
  18. [UE4]多播(广播)
  19. OPML文件
  20. 【C】——fread函数和read函数的区别

热门文章

  1. Linux网络安全篇,配置Yum源(一),本地Yum源
  2. 彻底卸载----LoadRunner
  3. 从谷歌面试翻车到offer收割的心路历程
  4. coding 注意事项(总结中)
  5. 搭建WEB、NFS共享、sersync实时同步以及全网定时备份服务流程
  6. centos7用户管理及root忘记密码恢复
  7. 漫谈LiteOS-Huawei_IoT_Link_SDK_OTA 开发指导
  8. python第三方库安装与卸载
  9. response没有实现跳转,而是提示浏览器下载文件
  10. Django文档阅读-Day3