数学--数论-- HDU6298 Maximum Multiple 打表找规律
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 打表找规律的更多相关文章
- 数学--数论--HDU-2698 Maximum Multiple(规律)
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...
- 数学--数论--HDU - 6124 Euler theorem (打表找规律)
HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...
- 数学--数论--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 ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- [国家集训队]整数的lqp拆分 数学推导 打表找规律
题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- OpenJ_POJ C16B Robot Game 打表找规律
Robot Game 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/B Description Sgeoghy has addi ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
随机推荐
- Vulnhub FristiLeaks靶机渗透
VM上配置 VMware users will need to manually edit the VM's MAC address to: 08:00:27:A5:A6:76 VM上选择本靶机,编辑 ...
- 2016蓝桥杯报纸页数(C++C组)
题目: 报纸页数X星球日报和我们地球的城市早报是一样的,都是一些单独的纸张叠在一起而已.每张纸印有4版.比如,某张报纸包含的4页是:5,6,11,12,可以确定它应该是最上边的第2张报纸.我们在太空中 ...
- python 写一个生成大乐透号码的程序
""" 写一个生成大乐透号码的程序 生成随机号码:大乐透分前区号码和后区号码, 前区号码是从01-35中无重复地取5个号码, 后区号码是从01-12中无重复地取2个号码, ...
- Python 0(安装及初步使用+学习资源推荐)
不足之处,还请见谅,请指出不足.本人发布过的文章,会不断更改,力求减少错误信息. Python安装请借鉴网址https://www.runoob.com/python/python-install.h ...
- JPA入门例子(采用JPA的hibernate实现版本) --- 会伴随 配置文件:persistence.xml
JPA入门例子(采用JPA的hibernate实现版本) 分类: j2se2011-03-30 16:09 45838人阅读 评论(9) 收藏 举报 jpahibernate数据库jdbcjava框架 ...
- I/O流之--转换流:InputStreamReader 和InputStreamWriter
I/O流之--转换流:InputStreamReader 和InputStreamWriter 分类: java2014-07-01 15:30 815人阅读 评论(0) 收藏 举报 目录(?)[ ...
- Tomcat5启动流程与配置详解
标签:配置 tomcat 休闲 职场 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://zhangjunhd.blog.51cto. ...
- 【Java】Junit单元测试
什么是单元测试? 单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证. 对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体含义,如C语言中单元指一个函数,Ja ...
- 利用 Github 网络钩子实现自动化部署
GitHub 的网络钩子(webhook)功能,可以很方便的实现自动化部署.本文记录了使用 Node.js 的开发部署过程,当项目的 master 分支被推时,将在服务器进行自动部署 添加网路钩子 在 ...
- 干货:python面对对象类继承简介
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:python视觉算法 PS:如有需要Python学习资料的小伙伴可以加 ...