题意:

输入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. java 面向对象概述, 函数解析

    函数:class FunctionDemo { public static void main(String[] args) { /* int x = 4; System.out.println(x* ...

  2. 用数组来实现Stack

    1:Stack特点 stack:栈,是一种特殊的数据结构,有着先入后出的特点(first in last out).stack中栈底始终不变,只有一端能变化.栈顶在有数据push的时候增大,有数据po ...

  3. 微服务项目开发学成在线_day03 CMS页面管理开发

    springboot引入mangodb依赖坐标:在spring-boot集成条件下,使用mongodb的DAO层开发. swagger查看接口文档,请求地址:http://localhost:3100 ...

  4. Python中的encode和decode

    原文地址:http://www.cnblogs.com/tingyugetc/p/5727383.html 1.Python3中对文本和二进制数据进行了比较清晰的区分,文本总是 unicode ,由  ...

  5. 如何在Foxwell NT650 OBD2扫描仪上查看实时PID数据?

    这是在Foxwell NT650扫描仪上使用实时数据菜单的操作指南 . 实时数据菜单使您可以查看和记录来自电子控制模块的实时PID数据.菜单选项通常包括: 完整的数据清单 自定义数据列表 如何使用“完 ...

  6. 微信小程序2048开发进度(一)

    父亲是个体劳动者,他的兴趣就是下象棋,针对平时兴趣,我想做一款自己的2048小游戏,在慕课网观看了2048小游戏的讲解,以及关于开发小游戏的理论知识,对开发一款小游戏有了基本的认识.

  7. Maven--归类依赖

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  8. ios 真机使用相机闪退问题

    需要增加权限 在info文件增加 主要前面的key 后面的cameraDesciption只是一段描述 随便写就可以

  9. 论文翻译——Recursive Deep Models for Semantic Compositionality Over a Sentiment Treebank

    Abstract Semantic word spaces have been very useful but cannot express the meaning of longer phrases ...

  10. matlab 启动图标

    matlab 启动图标 cat /usr/share/applications/Matlab.desktop [Desktop Entry] Type=Application Name=Matlab ...