[ZOJ2069]Greatest Least Common Multiple
[ZOJ2069]Greatest Least Common Multiple
题目大意:
给定一个正整数\(n\),将其分成若干个正整数之和,最大化这些数的LCM。保证答案小于\(10^{25}\)。
思路:
由于答案\(\le10^{25}\),则\(n\le540\)。
可以证明一定存在一种方案使得拆分后各数互质且答案最大。
\(f[i][j]\)表示考虑前\(i\)种质数,组成的和为\(j\)的答案。转移时枚举从\(n\)中拆出这个质数的多少次方。
由于OJ上不支持__int128,所以直接最后打表即可。
打表程序:
#include<cstdio>
#include<cctype>
#include<numeric>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=541,P=N;
typedef long long int64;
typedef __int128 int128;
int128 f[P][N];
int128 gcd(const int128 &a,const int128 &b) {
return b?gcd(b,a%b):a;
}
inline int128 lcm(const int128 &a,const int128 &b) {
return a/gcd(a,b)*b;
}
void print(const int128 &x) {
if(x>9) print(x/10);
putchar(x%10+'0');
}
bool vis[N];
int p[P];
inline void sieve() {
for(register int i=2;i<N;i++) {
if(!vis[i]) p[++p[0]]=i;
for(register int j=1;j<=p[0]&&p[j]*i<N;j++) {
vis[p[j]*i]=true;
if(i%p[j]==0) break;
}
}
}
int main() {
sieve();
std::fill(&f[0][0],&f[0][N],1);
for(register int i=1;i<=p[0];i++) {
f[i][0]=f[i-1][0];
for(register int j=1;j<N;j++) {
f[i][j]=std::max(f[i-1][j],f[i][j-1]);
for(register int q=p[i];q<=j;q*=p[i]) {
f[i][j]=std::max(f[i][j],f[i-1][j-q]*q);
}
}
}
putchar('{');
for(register int i=0;i<N;i++) {
if(i!=0) putchar(',');
putchar('"');print(f[p[0]][i]);putchar('"');
}
puts("};");
return 0;
}
[ZOJ2069]Greatest Least Common Multiple的更多相关文章
- [Intermediate Algorithm] - Smallest Common Multiple
题目 找出能被两个给定参数和它们之间的连续数字整除的最小公倍数. 范围是两个数字构成的数组,两个数字不一定按数字顺序排序. 例如对 1 和 3 —— 找出能被 1 和 3 和它们之间所有数字整除的最小 ...
- K - Least Common Multiple
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- [UCSD白板题] Least Common Multiple
Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...
- hdu1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDOJ2028Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】
题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- Least Common Multiple
地址:http://www.codewars.com/kata/5259acb16021e9d8a60010af/train/python 题目: Write a function that calc ...
随机推荐
- jenkins上节点显示swap空间不足解决方案
查看内存占用情况:free -m 1.swap分区原理: swap分区在系统的物理内存不够用的时候,把物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时 ...
- SVG 图像入门教程
http://www.ruanyifeng.com/blog/2018/08/svg.html 一.概述 SVG 是一种基于 XML 语法的图像格式,全称是可缩放矢量图(Scalable Vector ...
- plsql的汉化问题
1:汉化工具下载地址:https://www.allroundautomations.com/bodyplsqldevreg.html 汉化吗.然后选择chinese就行了: 2:对安装(解压缩好的哦 ...
- RSA javascript加密 lua解密
一个在线RSA非对称加密解密,可以用这个地址生成公钥和私钥 https://blog.zhengxianjun.com/online-tool/rsa/ javascript加密 jsencrypt. ...
- Centos6安装SaltStack
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install ...
- [转] 谈谈JS中的函数节流
函数节流的目的 从字面上就可以理解,函数节流就是用来节流函数从而一定程度上优化性能的.例如,DOM 操作比起非DOM 交互需要更多的内存和CPU 时间.连续尝试进行过多的DOM 相关操作可能会导致浏览 ...
- 【Arduino】开源开发板说明
来自世界各地的新型微控制器层出不穷,这类开发板多数都是通过Arduino改进的版本,例如由Arduino所改良的Yún一样,主要是针对网状网路进行改进或升级了其它无线功能. 但一些开发板也有着其独到的 ...
- JMeter性能测试,验证请求数据的准确性(wc命令)
wc: 该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取. wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. - c 统计字节数. - l 统计行 ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- React 入门实例教程(转载)
现在最热门的前端框架,毫无疑问是 React . 上周,基于 React 的 React Native 发布,结果一天之内,就获得了 5000 颗星,受瞩目程度可见一斑. React 起源于 Face ...