• nyist 70 阶乘因式分解(二)


    阶乘因式分解(二)

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:3
     
    描述

    给定两个数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





    #include <stdio.h>
    int main( )
    {
    int count,n,m,i,ii,t;

    scanf("%d",&t);
    while(t--)
    {
    count=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    { ii=i ;
    if(ii%m==0) // 逐个 检验
    {
    count++; // +1
    ii=ii/m; // 新ii 是否 含m的某次方

    while(ii%m==0) // m的某次方
    { count++; ii=ii/m; } //
    }


    }
    printf("%d",count);
    }

    }


    ***************************************


    #include <iostream>
    using namespace std;
    int main()
    {
    int m,n,k,s,sum;
    cin >> s;
    while(s--)
    {
    sum=0;
    cin >> n >> m; //m是素数
    while(n)
    {
    k=n/m;
    sum+=k;
    n=k;
    }
    cout << sum << endl;
    }
    }

    ***************************************

    #include<stdio.h>

    int main()
    {
    int s;
    long long n,m,ans;

    scanf("%d",&s);
    while(s--)
    {
    scanf("%lld%lld",&n,&m);
    ans=0;
    while(n>=m)
    {
    ans+=n/m;
    n/=m;
    }
    printf("%lld ",ans);
    }
    return 0;
    }


    *********************88888

    这里好几个题全是调用这个式子,不过为啥呢?这个式子分析不懂,高手给个回复吧!
    cin>>a>>b;
    k=0;
    do
    {
    a/=b;
    k+=a;
    }while(a);
    cout<<k<<endl;


    *********************************8********************************************************

    #include<stdio.h>
    main()
    {
    int N,m,s,n;
    scanf("%d",&N);
    while(N--)
    { s=0;
    scanf("%d%d",&n,&m);
    do { n/=m ;
    s+=n ; }
    while(n) ;

    printf("%d ",s);
    }
    }


    ***************************88

    ****************************************

    #include<stdio.h>
    main()
    {
    int N,m,s,n;
    scanf("%d",&N);
    while(N--)
    { s=0;
    scanf("%d%d",&n,&m);
    while(n)
    { n/=m ;
    s+=n ; }


    printf("%d ",s);
    }
    }

    ***************************

    #include<stdio.h>

    int main()
    {
    int N,n,m;
    scanf("%d",&N);
    while (N--)
    {
    scanf("%d%d",&n,&m);
    int ans;
    ans=0;
    while(n>=m)
    {
    ans+=n/m;
    n/=m;
    }
    printf("%d ",ans);
    }
    return 0;
    }


    ********************************

    /*
    http://www.cnblogs.com/liwenxin/archive/2011/04/12/jiechengyinshifenjie.html
    */


    #include <iostream>
    using namespace std;
    int jc(int n,int m)
    {
    int sum=0;
    while(n)

    {

    sum+=n/m;
    n/=m;
    }

    return sum;
    }


    int main()
    {
    int s;
    cin>>s;
    while(s--)
    {
    int n,m;
    cin>>n>>m;
    cout<<jc(n,m)<<endl;
    }
    return 0;
    }

  • 相关阅读:
    java 下载文件
    springfox-swagger之swagger-bootstrap-ui
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    An internal error occurred during: Initializing Java Tooling.
    hexo 报错 Cannot read property 'replace' of null
    点击此电脑,查看属性获取计算机的基本信息,可以获取那些计算机基础知识信息呢
    微信、qq可以上网,但是浏览器却不能上网怎么办
    maven打包如何跳过测试
    Ubuntu16.04安装和配置RabbitMQ
    Jenkins持续集成实践之java项目自动化部署
  • 原文地址:https://www.cnblogs.com/2014acm/p/3901475.html
Copyright © 2020-2023  润新知