题意:给定N个数a1,a2,a3...aN,现在要求最小的n满足 n!/(a1!*a2!*...*aN!) 是一个正整数的最小的n。

分析:这题的想法很明确,就是分解a1!*a2!*...*aN!,把其分解成质因子相乘的形式,这个都很熟悉了,然后就是对每一个质因子二分搜索出一个数字下界,最后求其中最大的一个数,问题的关键就是如何分解这样一个表达式成一个质因子相乘的形式。使用一个cnt数组来表示每一个数的在乘积中出现的次数,然后从后往前假设一个数出现了k次,那么如果这个数是素数则不用更新,如果一个数是合数则将其分解成两部分,一个是该数最小的质因子,一个是除以这个质因子之后的值,接着一直做下去,就能够把所有的素因子全部统计起来,最后再对每一个素因子都二分搜索。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
using namespace std; typedef long long LL;
const int N = ;
vector<int>vv;
LL cnt[N];
int p[N];
int Max;
LL sum;
int n; void pre() {
for (int i = ; i < N; ++i) {
if (!p[i]) {
p[i] = i;
vv.push_back(i);
}
for (int j = ; i*vv[j] < N; ++j) {
p[i*vv[j]] = vv[j];
if (i % vv[j] == ) break;
}
}
} LL cal(LL mid, LL base) {
LL ret = ;
while (mid) {
ret += (mid /= base);
}
return ret;
} void deal() {
for (int i = Max; i >= ; --i) {
if (p[i] != i) {
cnt[p[i]] += cnt[i];
cnt[i/p[i]] += cnt[i];
}
}
} LL get(LL base, LL x) {
LL l = , r = sum;
LL ret;
while (l <= r) {
LL mid = (l + r) >> ;
if (cal(mid, base) >= x) {
ret = mid;
r = mid - ;
} else {
l = mid + ;
}
}
return ret;
} int main() {
pre();
scanf("%d", &n);
int x;
for (int i = ; i < n; ++i) {
scanf("%d", &x);
sum += x;
Max = max(Max, x);
++cnt[x];
}
for (int i = Max-; i >= ; --i) {
cnt[i] += cnt[i+];
} // 模拟阶乘,1-n之间每个数都有一个
deal();
LL ret = ;
for (int i = ; i < vv.size(); ++i) {
ret = max(ret, get(vv[i], cnt[vv[i]]));
}
printf("%I64d\n", ret);
return ;
}

最新文章

  1. Hadoop学习笔记—18.Sqoop框架学习
  2. 第一章-第十一题(请问 “软件” 和 “软件工程” 这些词汇是如何出现的 - 何时、何地、何人)--By 侯伟婷
  3. 用js生成PDF的方案
  4. message from server: &quot;Host &#39;XXX&#39; is not allowed to connect to this MySQL server
  5. NSMutableAttributedString 富文本的使用
  6. 函数调用方式__stdcall、__cdel
  7. Java--多线程读取网络图片并保存在本地
  8. thinkPHP实现瀑布流的方法
  9. 应用程序域(Application Domain)
  10. dojo grid 分页
  11. java编程思想第四版中net.mindview.util包
  12. css3绘制中国结
  13. jQuery 侧栏菜单点击body消失
  14. 第一百三十一节,JavaScript,封装库--CSS
  15. [iOS Animation]-CALayer 图层几何学
  16. ThinkPHP框架前后台的分页调用
  17. 在linux下管理iphone
  18. 从零开始搭建etcd分布式存储系统+web管理界面
  19. 我的MQ笔记
  20. [svc]ssh批量分发key/批量用户管理

热门文章

  1. Java中常见数据结构:list与map
  2. PHP文件系统处理相关操作
  3. JavaEE基础(十六)/集合
  4. [UML]转:浅谈UML的概念和模型之UML九种图
  5. HASH表原理(装)
  6. linux命令总结2
  7. Ubuntu镜像使用帮助
  8. boost库学习之开篇
  9. Reading package lists... Error! 解决方案
  10. ubuntu下安装花生壳