这题明白的意思就是求n!在b进制下的后缀零的个数。

即最大的n!%(b^k)==0的k的值。我们需要将如果要构成b这个数,肯定是由一个个质因子相乘得到的。我们只需要求出b的质因子,然后分析n!中可以组成一个b的因子由多少个就可以了。

因为b是10的12次方,所以b的质因子某个因子大于了10的6次方,那肯定是质数了,所以我们只需要筛选出10的6次方以内的质因子就可以了,并且记录下每个质因子的基数。

最后是记录n!由多少个b的素因子组成并除以它的基数,取其中的最小值。

n!中有多少个素因子(假设素因子是x),我们只需要算出1到n中所有a*x^b(a<x)的b的总和,我们不必将某个x^b一个个算出来,我们只需要算出(n/x)到(n/x^b)的总和即可。

附上AC代码(感觉写得不怎么样

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<fstream>
using namespace std;
typedef long long ll;
ll prime[];
struct node
{
ll num;
ll data;
} a[];;
bool vis[];
ll b;
ll init()
{
memset(vis,false,sizeof(vis));
ll k=,i;
for(i=; i<=; i++)
{
if(!vis[i])
{
prime[k++]=i;
for(ll j=; i*j<=; j++)
vis[i*j]=true;
}
} return k;
}
int main()
{
ll k,i,j,n,cnt,sum,t=,r,mini;
t=init();//线性筛出质数
while(scanf("%I64d%I64d",&n,&b)!=EOF)
{
cnt=;
sum=;
r=b;
for(i=; i<t&&b!=; i++)
{
if(b%prime[i]==)
{
a[cnt].data=prime[i];
a[cnt].num=;
while(b%prime[i]==)
{
a[cnt].num++;
b/=prime[i];
}
cnt++;
}
}
if(b!=)
a[cnt].data=b,a[cnt++].num=;
b=r;
for(i=; i<cnt; i++)
{
for(j=a[i].data,sum=,r=; j<=n; j*=a[i].data)
{
sum+=(n/j);
if(n/j<a[i].data)//为了防止j发生溢出
break;
}
if(i==)
mini=sum/a[i].num;
else
mini=min(mini,sum/a[i].num); }
printf("%I64d\n",mini); } }

Codeforces Round #538 (Div. 2) CTrailing Loves (or L'oeufs?)的更多相关文章

  1. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  2. Codeforces Round #538 (Div. 2) (CF1114)

    Codeforces Round #538 (Div. 2) (CF1114)   今天昨天晚上的cf打的非常惨(仅代表淮中最低水平   先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...

  3. Codeforces Round #538 (Div. 2)

    目录 Codeforces 1114 A.Got Any Grapes? B.Yet Another Array Partitioning Task C.Trailing Loves (or L'oe ...

  4. Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?) (分解质因数)

    题目:http://codeforces.com/problemset/problem/1114/C 题意:给你n,m,让你求n!换算成m进制的末尾0的个数是多少(1<n<1e18    ...

  5. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  6. Codeforces Round #538 (Div. 2) E 随机数生成

    https://codeforces.com/contest/1114/problem/E 题意 交互题,需要去猜一个乱序的等差数列的首项和公差,你能问两种问题 1. 数列中有没有数比x大 2. 数列 ...

  7. Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零

    https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...

  8. Codeforces Round #538 (Div. 2) D. Flood Fill 【区间dp || LPS (最长回文序列)】

    任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory ...

  9. Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】

    一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: #include < ...

随机推荐

  1. 深度学习实践-物体检测-faster-RCNN(原理和部分代码说明) 1.tf.image.resize_and_crop(根据比例取出特征层,进行维度变化) 2.tf.slice(数据切片) 3.x.argsort()(对数据进行排列,返回索引值) 4.np.empty(生成空矩阵) 5.np.meshgrid(生成二维数据) 6.np.where(符合条件的索引) 7.tf.gather取值

    1. tf.image.resize_and_crop(net, bbox, 256, [14, 14], name)  # 根据bbox的y1,x1,y2,x2获得net中的位置,将其转换为14*1 ...

  2. Axis2 服务器端抛出ServiceClass object does not implement问题解决方法

    在用eclipse配合Axis2进行开发的时候,编译通过,启动tomcat也顺利,但是就是在调用服务器端的服务时,会抛出: The ServiceClass object does not imple ...

  3. AlphaGo的前世今生(三)AlphaGo Zero: AI Revolution and Beyond

    这是本专题的第三节,在这一节我们将以David Silver等人的Natrue论文Mastering the game of Go without human knowledge为基础讲讲AlphaG ...

  4. PHP5.5.38版本Zend Guard loader for 5.5安装(详细)

    第一次在博客园写东西记录自己,不,可以说第一次在网上写东西记录自己,我只是个菜鸟,具体的不太懂, 但是作为一个菜鸟我肯定把我遇到的问题给详细的表述出来,大神勿喷.在安装Zend Guard loade ...

  5. infinite-loading 插件

    <template> <div id="cart" class="has-top"> <!-- <v-header titl ...

  6. R语言-饼图

    1.饼图 > browsers<-read.table("browsers.txt",header=TRUE) > browsers<-browsers[o ...

  7. mysql Table 'user' is marked as crashed and should be repaired

    myisamchk -f x:\xxxxxxxxx\MySQL\data\mysql\*.MYI

  8. my.conf配置信息

    # mysql conf /etc/my.cnf# Created by http://www.wdlinux.cn# Last Updated 2010.06.01 [client]port = 3 ...

  9. ES6学习笔记(函数)

    1.函数参数的默认值 ES6 允许为函数的参数设置默认值,即直接写在参数定义的后面. function log(x, y = 'World') { console.log(x, y); } log(' ...

  10. 变邻域搜索(Variable neighborhood search)

    变邻域搜索(Variable neighborhood search)VNS是Hansen等提出的一种元启发近似算法,它通过在不同的邻域结构内跳转搜索, 能够避免陷入局部最优解. 算法主要分为两部分: ...