C. Trailing Loves (or L'oeufs?)

题目传送门

题意:

求n!在b进制下末尾有多少个0?

思路:

类比与5!在10进制下末尾0的个数是看2和5的个数,那么

原题就是看b进行质因数分解后,每个因数个数的最小值

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1000005
ll pri[N];
ll cnt[N];
ll tot;
void getpri(ll x)
{
memset(cnt,,sizeof(cnt));
memset(pri,,sizeof(pri));
for(ll i=;i*i<=x;i++)
{
while(x%i==)
{
pri[tot]=i;
cnt[tot]++;
x/=i;
}
if(cnt[tot]) tot++;
}
if(x>) pri[tot]=x,cnt[tot++]++;
}
ll solve(ll x,ll p)
{
ll res=;
while(x)
{
res+=x/p;
x/=p;
}
return res;
}
int main()
{
ll n,b;
while(~scanf("%lld %lld",&n,&b)){
tot=;
getpri(b);
ll maxn=1e18;
/*for(int i=0;i<tot;i++)
cout<<pri[i]<<" "<<cnt[i]<<endl;*/
for(ll i=;i<tot;i++)
{
maxn=min(maxn,solve(n,pri[i])/cnt[i]);
}
printf("%lld\n",maxn);
} return ;
}

C. Trailing Loves (or L'oeufs?) (质因数分解)的更多相关文章

  1. CF 1114 C. Trailing Loves (or L'oeufs?)

    C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...

  2. CF#538(div 2) C. Trailing Loves (or L'oeufs?) 【经典数论 n!的素因子分解】

    任意门:http://codeforces.com/contest/1114/problem/C C. Trailing Loves (or L'oeufs?) time limit per test ...

  3. Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论

    https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...

  4. 【Codeforces 1114C】Trailing Loves (or L'oeufs?)

    [链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...

  5. CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数

    题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...

  6. 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    ...

  7. Trailing Loves (or L'oeufs?)

    The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...

  8. C. Trailing Loves (or L'oeufs?)

    题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...

  9. Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

    大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...

随机推荐

  1. ArrayUtils工具类更加方便的操作数据

    不废话,上代码: package com.jxd; import org.apache.commons.lang3.ArrayUtils; public class TestArr { /** * A ...

  2. Beats:如何创建一个定制的Elastic Beat

    Beats作为Elastic Stack家族中重要的部分.它可以和方便地让我们把我们的数据发送到Elasticsearch或Logstash之中.如果我们想要生成自己的Beat,请使用GitHub的b ...

  3. orm中 如何模糊匹配某一年的用户和某一事时间段的用户

    导入Q查询

  4. Dubbo学习-1-基础知识

    分布式基础理论 1.什么是分布式系统: 分布式系统是若干独立计算机的集合,这些计算机对于用户来说就像是单个相关系统.分布式系统是建立在网络之上的软件系统 随着互联网发展,网站应用规模的不断扩大,常规的 ...

  5. OC + RAC (二) Command 命令的用法

    -(void)_test2{ ///////////////////////////////////////Command 命令的用法 注意使用command.executionSignals去订阅时 ...

  6. jsp文件断点上传

    之前仿造uploadify写了一个HTML5版的文件上传插件,没看过的朋友可以点此先看一下~得到了不少朋友的好评,我自己也用在了项目中,不论是用户头像上传,还是各种媒体文件的上传,以及各种个性的业务需 ...

  7. [CF959D]Mahmoud and Ehab and another array construction task题解

    解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...

  8. docker运行spring boot 包镜像出现no main manifest attribute问题

    问题: 在进行docker部署的时候,开始对项目进行打包,在启动该镜像时 [root@topcheer docker]# docker run -it 00494e3d4550no main mani ...

  9. Jenkins slave-agent.jnlp 无法安装为服务(install as a service)

    问题: 在部署持续集成环境,配置slave节点时遇到一个问题,slave-agent.jnlp可以正常启动运行(不能正常启动的点这里) 但是在保存为系统服务时,slave-agent.jnlp点击[i ...

  10. 《数据结构与算法(C语言版)》严蔚敏 | 第四章课本案例

    //二叉树的顺序存储表示 #define MAXTSIZE 100 typedef TElemtype SqBiTree[MAXTSIZE]; SqBiTree bt; //二叉树的二叉链表存储表示 ...