zoukankan      html  css  js  c++  java
  • oj Problem 1037

    Description

    n的阶乘定义为n!=1*2*3*……*n 如3!=6 n!通常最后会有很多0,如5!=120 最后有一个0,现在统计n!去除末尾的0后,最后k位是多少

    Input

    第一行包括两个数n,k

    Output

    如果n!不止k位,则输出最后k位,如果不足k位,则高位补零,补足k位后输出 注意!这里与阶乘统计1有区别!

    Sample Input

    7 2
    

    Sample Output

    04
    

    HINT

    7!为5040,去除末尾的0为504,最后两位为04

    100%满足1< =n< =1400000 1< =k< =10

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<stdlib.h>
    long long fun( int k )
    {
    long long t = 1;
    for( int i = 1; i <= k; i++ )
    t *= 10;
    return t;
    }
    int main()
    {
    long long n, k;
    scanf( "%lld%lld", &n, &k );
    long long i, j = 1, t;
    long long result = 1;
    for(i = 1 ; i <= n ; i++)
    {
    t = i ;
    while( t % 10 == 0 )
    t /= 10;
    t %= 1000000000;
    result *= t;
    while( result % 10 == 0 )
    result /= 10;
    result %= 1000000000;
    }
    j = fun( k );
    result %= j;
    while( j / 10 > result )
    {
    printf( "0" );
    j /= 10;
    }
    printf( "%lld\n", result );
    system( "pause" );
    return 0;
    }

    不解释。就是外函数应该是longlong就对了,让我wa好多次

  • 相关阅读:
    eclipse tomcat插件
    eclipse.ini
    iBatis杂记
    oracle 10g express 下载网址
    免费ftp客户端 winscp
    maven web app 发布到Tomcat
    sqlserver获取本月最后一天
    ArrayCollection和ComboBox
    flex框架 Cairngorm
    HDU3420 Bus Fair
  • 原文地址:https://www.cnblogs.com/zsj576637357/p/2318142.html
Copyright © 2011-2022 走看看