zoukankan      html  css  js  c++  java
  • 阶乘因式分解(二)

    描述

    给定两个数n,m,其中m是一个素数。

    将n(0<=n<=2^31)的阶乘分解质因数,求其中有多少个m。

    注:^为求幂符号。

     

     

     
    输入
    第一行是一个整数s(0<s<=100),表示测试数据的组数
    随后的s行, 每行有两个整数n,m。 
    输出
    输出m的个数
    样例输入
    3
    100 5
    16 2
    1000000000  13
    样例输出
    24
    15
    83333329

    求因式分解的因子当中素数M出现的次数,被m整出的为n/m个,被m*m整除的有n/(m*m)个。。。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    #include<queue>
    #include<deque>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<fstream>
    #include<memory>
    #include<list>
    #include<string>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    #define MAXN  22
    #define LLL 1000000000
    #define INF 1000000009
    #define eps 0.00000001
    /*
    给一个整数,求阶乘中一个素数出现多少次
    */
    LL n, m;
    int main()
    {
        int T;
        cin >> T;
        while (T--)
        {
            cin >> n >> m;
            LL cnt = 0;
            while (n)
            {
                cnt += n / m;
                n /= m;
            }
            cout << cnt << endl;
        }
        return 0;
    }
  • 相关阅读:
    移动端(手机端)页面自适应解决方案1(rem布局)---750设计稿
    ionic4之ion-sliders
    ionic4 新建
    Object的多种方法
    angular的Hash 模式和 HTML 5 模式
    关于滚动条
    前端笔记(1-20)
    百度图片网址
    ImageLoader_显示图片
    viewpager_轮播
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6841831.html
Copyright © 2011-2022 走看看