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. Docker备份与迁移

    容器保存为镜像 通过以下命令将容器保存为镜像: docker commit [-m="提交的描述信息"] [-a="创建者"] 容器名称|容器ID 生成的镜像名 ...

  2. linux创建相关待同步目录

    [root@rsync-server-1 ~]# mkdir /data/{web,web_data}/redhat.sx -p [root@rsync-server-1 ~]# tree /data ...

  3. Mac sublime 安装包的时候出现 unable to download xxx (_ssl.c:548)

    Mac sublime 安装包的时候出现 unable to download xxx前置条件:[本文行文中,所使用的电脑环境为 mac](当然不排除,在其他系统下,依然可以采用这种解决方案) 今天想 ...

  4. AQS简介以及源码分析

    参考链接:https://www.jianshu.com/p/da9d051dcc3d 参考链接:https://www.cnblogs.com/waterystone/p/4920797.html

  5. 揭示编译器API

    编译器管道功能区 .NET编译器平台(“Roslyn”)通过提供一个API层,是一个传统编译器管道镜像,向你这样的消费者揭示了C#和Visual Basic编译器的代码分析. 这条管道的每一部分,现在 ...

  6. Js中window.location.href和window.location.replace的区别

    href相当于打开一个新页面,replace相当于替换当前页面:这里打开页面都是针对历史记录来说,在页面上看完全相同,只是浏览器的history表现不同如果在1.html中点击链接到2.html,然后 ...

  7. man LVCREATE

    LVCREATE(8)                                                        LVCREATE(8) NAME/名称       lvcreat ...

  8. 手动ubuntu 18.04修改登录锁屏界面效果(含登录背景修改)flat-remix

    前言 在ubuntu 18.04,可以通过修改/etc/alternatives/gdm3.css来进行修改 本来想直接使用flat-remix主题,但是只有这个登录界面没有达到作者演示的效果,所以手 ...

  9. C#防止窗口重复打开

    修改Program.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Windo ...

  10. 万能的gitignore文件模版

    ## .gitignore for Grails 1.2 and 1.3 # .gitignore for maven target/ *.releaseBackup # web applicatio ...