题目:https://jzoj.net/senior/#main/show/5791

题意:有n个正整数a[i],设它们乘积为p,你可以给p乘上一个正整数q,使p*q刚好为正整数m的阶乘,求m的最小值。

对于10%的数据,n<=10
对于30%的数据,n<=1000
对于100%的数据,n<=100000,a[i]<=100000

首先,p * q = m!,也就是 p 是 m! 的一个因数;

把 p 质因数分解,那么 m! 的每个对应质因数的次数都 >= p 中对应质因数的次数;

不必乘出来 p,只要把每个 a[i] 质因数分解即可;

对于 m!,统计质因数的次数就是 cnt[i] += m / pri[i] , m /= pri[i],证明之类的很好想啦。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const maxn=1e5+,inf=1e9;
int n,a[maxn],p[maxn],ans,mx,pri[maxn],cnt;
bool ck(int x)
{
if(x<mx)return ;
for(int i=,t,tmp;i<=x&&i<=mx;i++)
{
if(!p[i])continue;
t=; tmp=x;
while(tmp)t+=tmp/i,tmp/=i;
if(t<p[i]){/*printf("t=%d p[%d]=%d\n",t,i,p[i]);*/ return ;}
// printf("x=%d t=%d p[%d]=%d\n",x,t,i,p[i]);
}
return ;
}
int main()
{
freopen("factorial.in","r",stdin);
freopen("factorial.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
for(int j=;j*j<=a[i];j++)
while(a[i]%j==)p[j]++,a[i]/=j,mx=max(mx,j);
if(a[i]>)p[a[i]]++; mx=max(mx,a[i]);
}
int l=,r=inf;
while(l<=r)
{
int mid=((l+r)>>);
// printf("l=%d r=%d mid=%d ck=%d\n",l,r,mid,ck(mid));
if(ck(mid))ans=mid,r=mid-;
else l=mid+;
}
printf("%d\n",ans);
return ;
}

JZOJ 5791 阶乘 —— 因数的更多相关文章

  1. [JZOJ 5791] 阶乘

    题意:求一个最小的\(m\),保证\(\prod a[i] * x = m!\) 思路: 考虑\(m!\)里面有多少个东西?? \(m\)个. 且是一个排列. 那么求一个最小的\(m\)使得前面的式子 ...

  2. JZOJ 5791. 【NOIP2008模拟】阶乘

    5791. [NOIP2008模拟]阶乘 (File IO): input:factorial.in output:factorial.out Time Limits: 1000 ms  Memory ...

  3. 阶乘 求n!中质因数的个数

    在n!中末尾有几个0 取决于n!中5的个数(2肯定比5多) 所以遍历从1到n的数,看总共有几个5即可 ..N do j = i; == ) ++ret; j /= ; end end 有个nb的方法: ...

  4. bzoj 3283: 运算器 扩展Baby Step Giant Step && 快速阶乘

    3283: 运算器 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 184  Solved: 59[Submit][Status][Discuss] D ...

  5. n!(n的阶乘)

    我们在这里介绍一些关于n!的性质. 在计数问题中,经常需要用到n!.有必要了解n!在mod p下的一些性质.下面我们假设p是素数,n!=ape(a无法被p整除),并试图求解e和a mod p(把这个东 ...

  6. CodeForces - 633B A Trivial Problem 数论-阶乘后缀0

    A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. ...

  7. luogu1445 [violet]樱花 阶乘分解

    题目大意 求方程$$\frac{1}{x}+\frac{1}{y}=\frac{1}{N!}$$的正整数解的组数. 思路 咱们把式子整理得$$xy-(x+y)N!=0$$.$xy$和$x+y$?貌似可 ...

  8. [jzoj 6080] [GDOI2019模拟2019.3.23] IOer 解题报告 (数学构造)

    题目链接: https://jzoj.net/senior/#main/show/6080 题目: 题意: 给定$n,m,u,v$ 设$t_i=ui+v$ 求$\sum_{k_1+k_2+...+k_ ...

  9. 【数论】[因数个数]P4167樱花

    题目描述 求不定方程 \(\frac {1}{x} + \frac{1}{y} = \frac{1}{n!}\)的正整数解的个数 \(n \leq 100^6\) Solution 化简得 \(x * ...

随机推荐

  1. docker 转载

    写的非常好的一篇文章,不知道为什么被删除了.  利用Google快照,做个存档. 快照地址:地址 作者地址:青牛 什么是docker Docker 是一个开源项目,诞生于 2013 年初,最初是 do ...

  2. 小程序 textarea ios兼容解决

    今天遇到,在小程序里textarea会存在一定的兼容性问题,textarea有默认的内边距,在安卓和ios显示的时候,ios边距会比安卓的大很多. 解决办法: 通过 wx.getSystemInfoS ...

  3. 微信小程序 setData动态修改数据数组的值

    1.问题说明 有一组数据,用来存储图片路径,动态修改图片的路径来上传图片,而小程序JS只能通过事件获取时机和setData方法修改数据来改变view. 而用这样写的方式明显是错误的 2.解决办法 字符 ...

  4. python3返回值中的none

    浏览器返回null,python3返回none,懵了. google了很多资料,不明就里,这就是没基础的后果啊呀呀呀. 上阮一峰的截图,就这么理解下凑合吧:

  5. dual boot

    https://askubuntu.com/questions/1031993/how-to-install-ubuntu-18-04-alongside-windows-10 https://www ...

  6. E - Cricket Field

    Description   Once upon a time there was a greedy King who ordered his chief Architect to build a fi ...

  7. [BZOJ2594] [Wc2006]水管局长数据加强版(LCT + kruskal + 离线)

    传送门 WC这个题真是丧心病狂啊,就是想学习一下怎么处理边权,给我来了这么一个破题! ORZ hzwer 临摹黄学长代码233 但还是复杂的一匹 理一下思路吧 题目大意:给定一个无向图,多次删除图中的 ...

  8. Extended symmetrical multiprocessor architecture

    An architecture for an extended multiprocessor (XMP) computer system is provided. The XMP computer s ...

  9. [poj2505]A multiplication game_博弈论

    A mutiplication game poj-2505 题目大意:给定一个数n和p,两个选手每次可以将p乘上[2,9].最先使得p大于n的选手胜利. 注释:$1\le n\le 429496729 ...

  10. zoj——3557 How Many Sets II

    How Many Sets II Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...