题意:

输入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. nginx_tcp_proxy代理酸酸乳

    一.安装低版本的nginx(高版本不支持tcp代理模块:nginx_tcp_proxy_module)Nginx默认只支持http反向代理,要支持tcp反向代理,需在编译时增加tcp代理模块[ngin ...

  2. SJTU T4143 推箱子

    问题描述 推箱子是一款经典的小游戏.游戏要求玩家将若干个箱子推到指定的位置,并以箱子移动次数最少作为目标. 现在,我们只需要考虑一个简化的版本--只有一个箱子.对于一张给定的地图,你需要判断是否可以将 ...

  3. delphi数据类型列表

    Delphi 数据类型列表 分类 范围 字节 备注 简单类型 序数 整数 Integer -2147483648 .. 2147483647 4 有符号32位 Cardinal 0 .. 429496 ...

  4. JavaScript sort()方法总结

    sort() 方法用于对数组的元素进行排序. 语法:arrayObject.sort(sortby):参数sortby可选.规定排序顺序.必须是函数. 注:如果调用该方法时没有使用参数,将按字母顺序对 ...

  5. 关于gc中对象回收算法的认识

    之前学习java时,笔者看到很多学习资料说,gc判断object存活与否的算法是:给对象添加一个引用计数器,每当有一处地方引用它时,计数器值就加1,当引用失效时,计数器值就减1,当对象计数清零时,对象 ...

  6. 01 语言基础+高级:1-6 集合_day04【Map】

    day04 [Map] 主要内容 Map集合 教学目标 能够说出Map集合特点 使用Map集合添加方法保存数据 使用”键找值”的方式遍历Map集合 使用”键值对”的方式遍历Map集合 能够使用Hash ...

  7. 02-python-运算符与表达式

    目录 1. 比较运算符 2. 算数运算符 3. 赋值运算符 4. 位于运算符 5. 逻辑运算符 6. 成员运算符 7. 身份运算符 8. 运算符优先级 9. 输出输入 10. 数字类型转换及常用数学方 ...

  8. css 传数据套路

    <input type=hidden> 那么该标签就不会显示 但是我们可以用这个标签储存数据 这是一个利用标签元素隐藏

  9. swift bannerview 广告轮播图

    class BannerView: UIView,UIScrollViewDelegate{ //图⽚⽔平放置到scrollView上 private var scrollView:UIScrollV ...

  10. elasticsearch min_hash 应用分析

    需求作相似文本查询 爬虫作页面去重,会用到simhash,第一个想到的是用simhash算法 但在现有数据集(elasticsearch集群)上用simhash,成本高,simhash值还好计算,不论 ...