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

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

【题解】

证明:https://blog.csdn.net/qq_40679299/article/details/81167283
这题的话m比较大,
做个质因数分解就ok>_<
算n!有多少个x因子的话
以5为例子 (n=25)
25 20 15 10 5
把他们都除5
5 4 3 2 1
然后再除5
1
所以总共有6个
转换成代码就是
while(n>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 herenew 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());}}
}

转载于:https://www.cnblogs.com/AWCXV/p/10361188.html

【Codeforces 1114C】Trailing Loves (or L'oeufs?)相关推荐

  1. 【CF#538div2:C】Trailing Loves (or L'oeufs?)(质因数分解+分析)

    题目地址:https://codeforces.com/contest/1114/problem/C 题意 给出十进制的数n,和要转换的进制b,求n!转化成b进制之后末尾有多少个0 解题思路 就是求最 ...

  2. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  3. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  4. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  5. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  6. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  7. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  8. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  9. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  10. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

最新文章

  1. 学习python需要什么基础-学习python需要什么基础吗?老男孩Python
  2. sklearn特征的提取(下)
  3. Gym 101194D Ice Cream Tower
  4. 车载电脑中控软件_数字图书馆智能化系统集成-ipad中控软件
  5. 使用Java复制文件并在控制台显示文件进度
  6. 【JZOJ5882】雪人
  7. 消费者京东自营买到假茅台 茅台鉴定报告称确属假冒
  8. 第三届光明区创新创业大赛——聚各方力量,助光明璀璨
  9. c和cpp实现CPU核上绑定固定线程
  10. 根据E-R图设计数据库表
  11. 软件项目管理第4版课后习题-期末复习题型分册版-练习版无答案
  12. iOS 直播类APP开发流程
  13. Android APP一键退出的方法总结分析
  14. 支持向量机SMO算法
  15. IT十年人生过客-十七-软通我来了
  16. 【Web安全基础】PHP基础
  17. 开工第一周,我劝你离开“独裁”的老板
  18. 目标跟踪--CamShift
  19. 互联网域名注册:2018年,.ORG 域名无法备案了
  20. Excel单元格黄色叹号 绿色三角形 去掉方法

热门文章

  1. Zookeeper案例之监听配置中心
  2. 《轻松读懂spring》之 IOC的主干流程(上)
  3. Java中的JVM虚拟机
  4. Nginx+Tomcat负载平衡
  5. Ant十五大最佳实践
  6. 体系结构方案 - 临时性数据计算
  7. java创建线程的三种方式及其对照
  8. @Autowired与@Resource的差别
  9. HADOOP再进阶:本地Yum软件源安装Cloudera Manager 5
  10. nginx基于域名的虚拟主机配置实战