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

【题意】

问你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. $(document).ready 与 window.onload的区别?

    $(document).ready  = function(){}; DOM树加载完成时执行,此时文件不一定都已加载完成. window.onload = function(){}; DOM树加载完成 ...

  2. Tornado集成Apscheduler定时任务

    熟悉Python的人可能都知道,Apscheduler是python里面一款非常优秀的任务调度框架,这个框架是从鼎鼎大名的Quartz移植而来. 之前有用过Flask版本的Apscheduler做定时 ...

  3. idea ssm项目移包报错问题

    写完代码之后发现包结构太乱了  想要规划一下  结果报错 这里面的包路径都可以点进去,还是报找不到com.lf.company.entity.Business 后来发现是 在移动前和移动后都存在这个m ...

  4. Vue组件库elementUI 在el-row 或 el-col 上使用@click无效失效,

    问题: elementUI 在el-row 或者 el-col 上使用@click失效, 解决: 在click后面加上 .native .要使用@click.native=”handler()”才行, ...

  5. html5: table表格与页面布局整理

    传统表格布局之table标签排版总结:   默认样式: <style> table { max-width: 800px; border-spacing: 2px; border-coll ...

  6. HTML--使用提交按钮,提交数据

    在表单中有两种按钮可以使用,分别为:提交按钮.重置.这一小节讲解提交按钮:当用户需要提交表单信息到服务器时,需要用到提交按钮. 语法: <input type="submit" ...

  7. Map,Filter 和 Reduce

    Map会将一个函数映射到一个输入列表的所有元素上 map(function_to_apply, list_of_inputs) items = [1, 2, 3, 4, 5] squared = li ...

  8. [转]在 Linux 下使用 RAID

    转自:http://www.linuxidc.com/Linux/2015-08/122191.htm RAID 的意思是廉价磁盘冗余阵列(Redundant Array of Inexpensive ...

  9. ios cocos2d-x 多点触摸

    需要在 AppController.mm文件中添加一句多点触摸支持: [_view setMultipleTouchEnabled:true];

  10. java学习笔记_序列化

    如果父类没有实现Serializable接口,子类实现了Serializable接口,那么子类是可以序列化的. 但是如果想要反序列化,那么就需要父类支持默认构造函数. 因为在反序列化的过程中不会调用子 ...