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);elseputs("-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);elseputs("-1");}elseputs("-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. [国家集训队]整数的lqp拆分 数学推导 打表找规律

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

  3. paulzhou的数学?TAT? 【二分打表找规律】

    paulzhou的数学?TAT? Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Tota ...

  4. 点分治问题 ----------- P3727 曼哈顿计划E[点分治+博弈SG函数打表找规律]

    题目链接 解题思路: 1.首先对于每个操作我们实际上是一个博弈问题 对于k=1的操作就是很基础的NIM游戏就是找到一条链的异或和为0 对于k=2的操作通过达打表找规律: 如果s是奇数那么偶数的SG函数 ...

  5. Yet Another Meme Problem(打表找规律)

    Try guessing the statement from this picture http://tiny.cc/ogyoiz. You are given two integers AA an ...

  6. hdu_5894_hannnnah_j’s Biological Test(打表找规律)

    题目链接:hdu_5894_hannnnah_j's Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...

  7. D. Pythagorean Triples(1487D)(打表找规律 + 二分)

    D. Pythagorean Triples(1487D)(打表找规律 + 二分) 题目来源:D. Pythagorean Triples 题意: 给定一个 n,求满足以下条件的数对 (a, b, c ...

  8. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  9. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

最新文章

  1. 清除 Xcode 项目缓存
  2. Linux-/proc目录简介
  3. javascript中alert函数的替代方案,一个自定义的对话框的方法(引用)
  4. Web安全实践(13)嗅探,arp欺骗,会话劫持与重放攻击(上)
  5. 统计学习方法 第九章笔记: EM 算法
  6. 将Websocket与Spring Framework和Vuejs结合使用
  7. 视觉SLAM十四讲(1):预备知识
  8. stl vector 函数_vector :: back()函数以及C ++ STL中的示例
  9. php教程 二叉树,PHP ClassObject -- PHP 自排序二叉树的深入解析
  10. SaltStack Salt 开源管理框架修复2个严重漏洞,多款开源产品等受影响
  11. 机器学习--支持向量机实战(三)完整版SMO算法实现
  12. excel中的数据怎么导入matlab中,将excel中的数据导入matlab教程的方法步骤
  13. Word2019添加复选框
  14. 【免费-LOGO制作】——U钙网
  15. 无线路由器服务器连接线,无线路由器连接有线路由器怎么设置?
  16. gitlab服务: kex_exchange_identification: Connection closed by remote host
  17. 免费图片转pdf的方法?学会图片转pdf很重要
  18. android导入库项目,如何在android studio项目中导入开源库?
  19. 【惊呼】微信最多可以加多少好友,真正原因可能出乎你的想象!
  20. 隐藏在QQ2000当中的大秘密 !!!

热门文章

  1. Android开发之The application could not be installed: INSTALL_FAILED_VERSION_DOWNGRADE报错
  2. Android开发之ApiCloud模块开发之模块引用第三方库的问题
  3. vue 组件基本使用
  4. SpringBoot集成Thymeleaf
  5. servlet的执行过程
  6. adb shell读取返回值_shell学习笔记03(函数amp;shell工具amp;面试题)
  7. 流行的AJAX框架对比:jQuery,Mootools,Dojo,Ext JS
  8. Ajax联手SOA打造企业级应用
  9. springboot取yml中的值_@Value拜拜:更优雅的获取springboot yml中的值
  10. 鸿合怎么删掉linux6_鸿合电子白板怎么校准?鸿合电子白板校准的方法