【链接】 我是链接,点我呀:)

【题意】

问你n!的b进制下末尾的0的个数

【题解】

证明:https://blog.csdn.net/qq_40679299/article/details/81167283
这题的话m比较大,
做个质因数分解就ok>_0){
ans+=n/5;
n = n/5;
}

【代码】

import java.io.*;
import java.util.*; public class Main { static int N = (int)1e6;
static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static class Task{
public void solve(InputReader in,PrintWriter out) {
long n,m;
n = in.nextLong();m = in.nextLong();
ArrayList a = new ArrayList<>();
ArrayList d = new ArrayList<>();
for (long i = 2;i*i<=m;i++) {
if (m%i==0) {
a.add(i);
int cnt1 = 0;
while (m%i==0) {
m/=i;
cnt1++;
}
d.add(cnt1);
}
}
if (m>1) {
a.add(m);
d.add(1);
}
long ans = (long)1e18 + 100;
for (int i = 0;i <(int)a.size();i++) {
long ai = (long) a.get(i);
int pi = (int) d.get(i);
long nn = n;
long res = 0;
while (nn>0) {
res+=nn/ai;
nn/=ai;
}
ans = Math.min(ans, res/pi);
}
out.print(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public long nextLong() {
return Long.parseLong(next());
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 1114C】Trailing Loves (or L'oeufs?)的更多相关文章

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

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

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

  3. C. Trailing Loves (or L'oeufs?) (质因数分解)

    C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...

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

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

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

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

  6. 【Codeforces 444A】DZY Loves Physics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...

  7. 【Codeforces 446A】DZY Loves Sequences

    [链接] 我是链接,点我呀:) [题意] 让你找一段连续的区间 使得这一段区间最多修改一个数字就能变成严格上升的区间. 问你这个区间的最长长度 [题解] dp[0][i]表示以i为结尾的最长严格上升长 ...

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

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

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

随机推荐

  1. 【Poj1325】Machine Schedule机器调度

    目录 List Description Input Output Sample Input Sample Output HINT Solution Code Position: http://poj. ...

  2. JSP页面规格化

    http://doc.okbase.net/%E4%BA%BA%E7%94%9F%E9%9A%BE%E5%BE%97%E7%B3%8A%E6%B6%82/archive/123084.html htt ...

  3. JDK8 函数式接口

    JDK8中为了适应函数式响应编程模式,引入了函数式接口概念以增加Lambda表达式的功能.函数式接口其实本质上还是一个接口,但是它是一种特殊的接口:SAM类型的接口(Single Abstract M ...

  4. Django day29 视图,路由控制,响应器

    一:视图 1.视图的几种方式: (1) 第一种 from rest_framework.mixins import ListModelMixin, CreateModelMixin class Pub ...

  5. $CF1141C Polycarp Restores Permutation$

    \(problem\) 这题的大致意思就是已知数值差值 求1-n的排列 如果能构成排列 则输出这个排列.如果不能则输出-1 排列的值都是 大于1 而小于n的 而且没有相同的数字. 这题最关键的是 怎么 ...

  6. Eclipse 添加 YAML插件

    官网:https://github.com/oyse/yedit 离线版本:(链接: https://pan.baidu.com/s/1PJzkS1tI-VigZvfbYXUh9A 密码: gfep) ...

  7. [转]linux下ulimit命令详解

    转自:http://blog.chinaunix.net/uid-23842323-id-2656582.html 1,说明:ulimit用于shell启动进程所占用的资源.2,类别:shell内建命 ...

  8. JS——行内式注册事件

    html中行内调用function的时候,是通过window调用的function,所以打印this等于打印window,所以在使用行内注册事件时务必传入参数this <!DOCTYPE htm ...

  9. CSS——盒子居中显示

    嵌套中个的子盒子使用了绝对定位,父盒子使用了相对定位.那么子盒子如何居中显示: 1.距离左偏离50% 2.margin-right子盒子宽度的一半 <!DOCTYPE html> < ...

  10. mysql_基础2

    创建数据表: