题意:

输入n和m,求n!转换成m进制之后末尾有多少个0;

思路:

转换一下题意就可以看成,将n表示成x * (m ^ y),求y的最大值。^表示次方而不是异或;

这就比较好想了,将m分解质因数,对于每个质因数,设n!含有a个,m含有b个,则ans = min(ans, a / b);

  • 自己比赛的时候写的

    C - Trailing Loves (or L'oeufs?) GNU C++11 Accepted 46 ms 0 KB
    #include "bits/stdc++.h"
    using namespace std;
    typedef long long LL;
    map<LL, LL> mp, num;
    vector<LL> vc;
    int main() {
    LL n, m;
    scanf("%lld%lld", &n, &m);
    for (LL i = ; i * i <= m; i++) {
    if (m % i == ) {
    vc.push_back(i);
    while (m % i == ) {
    m /= i;
    mp[i]++;
    }
    }
    }
    if (m != ) {
    vc.push_back(m);
    mp[m]++;
    }
    for (int i = ; i < vc.size(); i++) {
    LL j = ;
    while (j <= n / vc[i]) {
    j *= vc[i];
    num[vc[i]] += n / j;
    }
    }
    LL ans = 1LL << ;
    for (LL i = ; i < vc.size(); i++) {
    ans = min(ans, num[vc[i]] / mp[vc[i]]);
    }
    printf("%lld\n", ans);
    return ;
    }

    其实没必要把各个因子保存下来。标程还是优很多的

  • 看了标程之后改的
    C - Trailing Loves (or L'oeufs?) GNU C++11 Accepted 31 ms 0 KB
    #include "bits/stdc++.h"
    using namespace std;
    typedef long long LL;
    const LL INF = 1LL << ;
    int main() {
    LL n, m, ans = INF;
    scanf("%lld%lld", &n, &m);
    for (LL i = ; i <= m; i++) {
    if (i * i > m) {
    i = m;
    }
    if (m % i == ) {
    int cnt = ;
    while (m % i == ) {
    m /= i;
    cnt++;
    }
    LL tmp = , mul = ;
    /*
    for (LL mul = i; mul <= n; mul *= i)
    这种写法应该更符合正常思维,但是因为n最高可以达到1e18,比较接近LL上限,mul可能乘i之前还小于n,乘完就爆LL了;
    */
    while (mul <= n / i) {
    mul *= i;
    tmp += n / mul;
    }
    ans = min(ans, tmp / cnt);
    }
    }
    printf("%lld\n", ans);
    return ;
    }

CF-1114C-Trailing Loves (or L'oeufs?)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. Trailing Loves (or L'oeufs?)

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

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

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

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

随机推荐

  1. poj2243前一道题升级(思维构造+ac自动机)

    题:http://acm.hdu.edu.cn/showproblem.php?pid=2243 题意:给出m个模式串,求长度小于n的且存在模式串的字符串数有多少个(a~z) 分析:我们反着来,用总的 ...

  2. java使用io流读取windows文件乱码问题

    出现原因: 在IDEA中,使用 FileReader 读取项目中的文本文件.由于IDEA的设置,都是默认的 UTF-8 编码,所以没有任何 问题. 但是,当读取Windows系统中创建的文本文件时,由 ...

  3. Python—使用列表构造栈数据结构

    class Stack(object): """ 使用列表实现栈 """ def __init__(self): self.stack = ...

  4. ZJNU 1160 - 不要62——中级

    取模判断,数组模拟 /* Written By StelaYuri */ #include<stdio.h> ]; int main(){ int n,m,i,s,t; ;i<;i+ ...

  5. python全局灰度线性变换——自由设定图像灰度范围

    全局线性变换的公式是s = (r-a)*(d-c)/(b-a)+c,其中a.b是原图片的灰度最小值和最大值,c.d是变换后的灰度值的最小值和最大值.r是当前像素点的灰度值,s是当前像素点变换后的灰度值 ...

  6. Win10用Windows照片查看程序(照片查看器)打开图片

    以上方法只能一个个添加,也有人说不好使,这里给出一个我写的批处理程序,反正我一直用着很好.   ::复制以下内容到记事本: @echo off&cd\&color 0a&cls ...

  7. PAT甲级——1001 A+B Format (20分)

    Calculate a+b and output the sum in standard format – that is, the digits must be separated into gro ...

  8. Django静态文件配置-request方法-ORM简介-字段的增删改查

    app的创建注意事项: 在Django新创建的app要在seetings.py中添加注册,才会生效 创建app:django-adminapp an startapp app名称 或者 python3 ...

  9. TPO1-3Timberline Vegetabtion on Mountain|have the advantage over

    The upper timberline, like the snow line, is highest in the tropics and lowest in the Polar Regions. ...

  10. Opencv笔记(十八)——轮廓的更多函数及其层次结构

    凸缺陷 前面我们已经学习了轮廓的凸包,对象上的任何凹陷都被成为凸缺陷.OpenCV 中有一个函数 cv.convexityDefect() 可以帮助我们找到凸缺陷.函数调用如下: hull = cv2 ...