题意:给定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 ;
}

codeforces 300E Empire Strikes Back 数论+二分查找的更多相关文章

  1. Codeforces 955C - Sad powers(数论 + 二分)

    链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...

  2. Codeforces Round #404 (Div. 2) C 二分查找

    Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18)  找到 1) [n<= m] cout<<n; 2) ...

  3. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

  4. CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)

    传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...

  5. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  6. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

  7. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找

    C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  9. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...

随机推荐

  1. 七牛开发文档php

    http://developer.qiniu.com/docs/v6/sdk/php-sdk.html#overview http://developer.qiniu.com/docs/v6/sdk/ ...

  2. js函数自执行

    在javascript里,任何function在执行的时候都会创建一个执行上下文,因为function声明的变量和function有可能只在该function内部,这个上下文,在调用function的 ...

  3. java产生随机数并求和

    设计思路: 先随机生成10个数,组成一个数组,然后用消息框显示数组内容,然后用循环计算数组元素的和,将结果也显示在消息框中. 程序流程图: 源程序代码: import javax.swing.*; p ...

  4. ASP.net 上传

    if (FileUpload1.HasFile) { string filename = FileUpload1.PostedFile.FileName; string dir_file = &quo ...

  5. windows下TCP服务器和客户端的实现

      服务器   1.初始化 WSAStartup(..)   2.创建Socket s = Socket ( .. )   3.绑定端口 ret = bind ( ... )   4.监听 ret = ...

  6. hiho一下,第115周,FF,EK,DINIC

    题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...

  7. linux内核中创建线程方法

    1.头文件 #include <linux/sched.h> //wake_up_process() #include <linux/kthread.h> //kthread_ ...

  8. HDU 4630 No Pain No Game 线段树 和 hdu3333有共同点

    No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. COM技术の组件

    什么是COM COM,Component Object Mode即组件对象模型.之所以称之为“模型”,是表明COM是一种编程规范(非具体代码),通过这种规范我们能够编写出语言无关的,可扩展的,内部变化 ...

  10. 织梦cms PHPcms 帝国cms比较

    现在建网站不需要请程序员从基础的程序开发做起了,有专业的建站工具,CMS是使用最广泛的建站工具.CMS是Content Management System 现在建网站不需要请程序员从基础的程序开发做起 ...