[jzoj5791]【NOIP2008模拟】阶乘 (数学)
Description
有n个正整数a[i],设它们乘积为p,你可以给p乘上一个正整数q,使p*q刚好为正整数m的阶乘,求m的最小值。
Input
共两行。
第一行一个正整数n。
第二行n个正整数a[i]。
Output
共一行
一个正整数m。
Sample Input
1
6
Sample Output
3
样例解释:
当p=6,q=1时,p*q=3!
Data Constraint
对于10%的数据,n<=10
对于30%的数据,n<=1000
对于100%的数据,n<=100000,a[i]<=100000
Code
//By Menteur_Hxy
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
#define R(i,a,b) for(register int i=(b);i>=(a);i--)
#define E(i,u) for(register int i=head[u];i;i=nxt[i])
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin)),p1==p2?EOF:*p1++)
using namespace std;
typedef long long LL;
char buf[1<<21],*p1,*p2;
inline int read() {
int x=0,f=1; char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
}
const int N=100010;
int n,tot,cnt;
int pri[N],vis[N],mip[N],p[N],M[N];
void resolve(int x) {
while(mip[x]!=x) {
if(!M[mip[x]]) p[++cnt]=mip[x];
M[mip[x]]++; x/=mip[x];
}
if(mip[x]==x&&x!=1&&x!=0) {
if(!M[mip[x]]) p[++cnt]=mip[x];
M[mip[x]]++;
}
}
bool jud(int x) {
F(i,1,cnt) {
int res=0,tmp=p[i];
while(tmp<=x) res+=x/tmp,tmp*=p[i];
if(res<M[p[i]]) return 0;
} return 1;
}
void init() {
mip[1]=1;
F(i,2,100000) {
if(!vis[i]) pri[++tot]=i,mip[i]=i;
for(register int j=1;j<=tot&&i*pri[j]<=100000;j++) {
vis[i*pri[j]]=1;
mip[i*pri[j]]=pri[j];
if(i%pri[j]==0) break;
}
}
}
signed main() {
freopen("factorial.in","r",stdin);
freopen("factorial.out","w",stdout);
n=read();
init();
F(i,1,n) resolve(read());
// jud(10);
// F(i,1,cnt) cout<<p[i]<<" ";cout<<endl;
int l=1,r=5e6;
while(l<=r) {
int mid=(l+r)>>1;
if(jud(mid)) r=mid-1;
else l=mid+1;
// printf("%d\n",mid);
}
printf("%d",l);
return 0;
}
[jzoj5791]【NOIP2008模拟】阶乘 (数学)的更多相关文章
- JZOJ 5791. 【NOIP2008模拟】阶乘
5791. [NOIP2008模拟]阶乘 (File IO): input:factorial.in output:factorial.out Time Limits: 1000 ms Memory ...
- JZOJ 5773. 【NOIP2008模拟】简单数学题
5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms Memory Limits ...
- JZOJ 5777. 【NOIP2008模拟】小x玩游戏
5777. [NOIP2008模拟]小x玩游戏 (File IO): input:game.in output:game.out Time Limits: 1000 ms Memory Limits ...
- JZOJ 5809. 【NOIP2008模拟】数羊
5809. [NOIP2008模拟]数羊 (File IO): input:sheep.in output:sheep.out Time Limits: 1000 ms Memory Limits: ...
- JZOJ 5793. 【NOIP2008模拟】小S练跑步
5793. [NOIP2008模拟]小S练跑步 (File IO): input:run.in output:run.out Time Limits: 2000 ms Memory Limits: ...
- JZOJ 5776. 【NOIP2008模拟】小x游世界树
5776. [NOIP2008模拟]小x游世界树 (File IO): input:yggdrasil.in output:yggdrasil.out Time Limits: 1500 ms Me ...
- JZOJ 5775. 【NOIP2008模拟】农夫约的假期
5775. [NOIP2008模拟]农夫约的假期 (File IO): input:shuru.in output:shuru.out Time Limits: 1000 ms Memory Lim ...
- JZOJ 5771. 【NOIP2008模拟】遨游
5771. [NOIP2008模拟]遨游 (File IO): input:trip.in output:trip.out Time Limits: 2000 ms Memory Limits: 2 ...
- JZOJ5776. 【NOIP2008模拟】小x游世界树
题目:[NOIP2008模拟]小x游世界树: 题目的附加题解给的很清楚,这里只给一个代码: #include<iostream> #include<cstdio> #inclu ...
随机推荐
- javac compiling error ( mising package)
javac 编译java源文件时,提示 package does not exist 的错误 Test.java import java.security.MessageDigest; import ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- 一个效果非常华丽的仿桌面APP,却胜似Launcher
开发Android APP的同学是否对于Launcher实现的绚丽效果而痴迷呢?什么.连Android Launcher是什么都不知道.好吧,拿起侬的手机.在解锁后的首页界面上左右滑动滑动,体验体验, ...
- user和userdebug区别
user:不可以root userdebug:可以root
- Drainage Ditches(网络流(EK算法))
计算最大流,EK算法模板题. #include <stdio.h> #include <string.h> #include <queue> using names ...
- java多线程编程之synchronized
synchronized是用来解决多线程情况下的线程安全问题的,它可以修饰方法也可以修饰语句块 , 那么什么情况下是线程安全和线程不安全呢 ? 方法内的变量是线程安全的 , 类的实例变量是非线程安全的 ...
- bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6
自己写了个Django系统,用到了Django-bootstrap3结果在浏览器控制台发现报错:bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaS ...
- 数据连接类 这里采用mysql
数据库通用操作类,自己参照几个通用类改写的,用起来还是蛮不错.... 这里用的mysql 要是其他数据库自行更改下就好 public class MySqlHelper { public stati ...
- angular js shopping
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- poj3009 Curling 2.0 深搜
PS:以前看到题目这么长就没写下去了.今天做了半天,没做出来.准备看题解,打开了网站都忍住了,最后还是靠自己做出来的.算是一点进步吧. 分析: 题目的意思没明白或者理解有偏差都没办法做题.看样例3和样 ...