题意:

输入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. GNU Autotool介绍

    参考文档: automake(GNU教程) 几句话说清楚17:用Makefile.am和configure.ac构建一个专业的Hello World Creatingamhello-1.0.tar.g ...

  2. 84.常用的返回QuerySet对象的方法使用详解:select_related, prefetch_related

    1.select_related: 只能用在一对多或者是一对一的关联模型之间,不能用在多对多或者是多对一的关联模型间,比如可以提前获取文章的作者,但是不能通过作者获取作者的文章,或者是通过某篇文章获取 ...

  3. 吴裕雄--天生自然ShellX学习笔记:Shell 文件包含

    和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号(.)和文件名中间有一空 ...

  4. ZJNU 1534 - Problem Robot--高级

    因为是从(0,0)点开始以1,3,9,27,....的步数走的 其实可以每走一步后,以机器人为中心,平面所有坐标全部缩小3倍 那么本应该走3步的路现在只需要走1步就可以到达那个点 那么对于机器人来说这 ...

  5. Django知识点_梳理

  6. rsync配置文件

    vim /etc/rsyncd.conf motd file = /etc/rsyncd.motd #设置服务器信息提示文件,在该文件中编写提示信息 transfer logging = yes #开 ...

  7. The website is API(4)

    1.淘宝商品信息定向爬虫 目标:获取淘宝搜索页面信息,提取其中的商品名称和价格 理解:淘宝的搜索接口 翻页的处理 技术路线:requests+re https://s.taobao.com/searc ...

  8. Centos内核更新

    内核更新操作后面补上.暂时记录删除多余内核操作 删除卸载多余内核 1.系统启动时,选择需要保留的内核进入系统,通过uname -a命令查看当前内核版本,以防误删 2. 使用rpm -qa | grep ...

  9. mysql 查询a表在b表中不存在的记录

    select * from tbl_user a where(select count(1) as cnt from tbl_order b where a.phone=b.phone)=0

  10. mysql绿色版安装及授权连接

    --安装包官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads --安装教程参见:https://www.cnblogs.co ...