数学--数论--HDU-2698 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");
}
}
数学--数论--HDU-2698 Maximum Multiple(规律)的更多相关文章
- hdu 6298 Maximum Multiple (简单数论)
Maximum Multiple Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 6298 Maximum Multiple(规律)
hdu6298 Maximum Multiple 题目传送门 题意: 给你一个整数n,从中找出可以被n整除的三个数x,y,z: 要求x+y+z=n,且x*y*z最大. 思路: 开始一看T到1e6,n也 ...
- 数学--数论--HDU - 6124 Euler theorem (打表找规律)
HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...
- 数学--数论--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 ...
- 数学--数论--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 - 6322 打表找规律
In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...
- 数学--数论--HDU 2197 本原串 (推规律)
由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串? 答案mod2008. 例如,100100不是本原串,因为他是由两个 ...
- 数学--数论--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 ...
- 数学--数论--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 ...
- 数学--数论--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! ...
随机推荐
- 使用mpvue开发小程序教程
从vue到mpvue再到微信小程序,这么几天下来感觉被搞晕了.三者之间的很多功能存在差异,项目也快接近尾声了,坑也踩了很多了,现在给后来的你们一点总结性经验: 1. 在模板中,动态插入HTML的v-h ...
- 创建堆(python)
创建最大(小)堆 二叉堆本质上是一种完全二叉树,存储方式并不是链式存储,而是顺序存储 堆操作:插入(叶子节点上调),删除(堆顶元素下沉) 堆创建:非叶子节点下沉(从最后一个非叶子节点开始) 最小堆: ...
- Spark 1.5 to 2.1.X
api差异参考官网地址:https://spark.apache.org/docs/2.1.1/sql-programming-guide.html#upgrading-from-spark-sql- ...
- hadoop(七)集群配置同步(hadoop完全分布式四)|9
前置配置:rsync远程同步|xsync集群分发(hadoop完全分布式准备三)|9 1. 分布式集群分配原则 部署分配原则 说明Namenode和secondarynamenode占用内存较大,建议 ...
- webpack踩坑 无法解析jquery及webpack-cli
最近在学习Vue,使用到webpack的时候,出现了错误,可能是3和4的版本问题 webpack-dev-server 安装好webpack-dev-server后,需要在package.json 的 ...
- ffmpeg 交叉编译 版本4.0.4
touch run.sh chmod 755 run.sh ./run.sh run.sh #!/bin/sh ./configure \ --arch=aarch64 \ --cpu=armv8-a ...
- 006-循环结构(下)-C语言笔记
006-循环结构(下)-C语言笔记 学习目标 1.[掌握]do-while循环结构 2.[掌握]for循环结构 3.[掌握]嵌套循环 一.do-while循环结构 do-while语法: 1 2 ...
- stand up meeting 1/7/2016
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 调研下滑条的存在问题,尝试替换方案 6 全面实行替换 ...
- 1327C - Game with Chips (构造)
题目大意:一个n*m的棋盘上有k个棋子,k个棋子相互关联,可以一起向上向下向左向右,当碰到边界时,如果继续移动会发生越界,那么该棋子会保持不动,其余棋子继续移动.问能否在2*n*m的移动次数内,使各个 ...
- 浏览器中 JS 的事件循环机制
目录 事件循环机制 宏任务与微任务 实例分析 参考 1.事件循环机制 浏览器执行JS代码大致可以分为三个步骤,而这三个步骤的往复构成了JS的事件循环机制(如图). 第一步:主线程(JS引擎线程)中执行 ...