zoukankan      html  css  js  c++  java
  • nefu118 n!后面有多少个0 数论

    n!后面有多少个0

    Time Limit 1000ms

    Memory Limit 65536K

    description

    从输入中读取一个数n,求出n!中末尾0的个数。

    input

    输入有若干行。第一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1<=n<=1000000000。

    output

    对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。

    sample_input

    3
    3
    100
    1024
    

    sample_output

    0
    24
    253

    数论题。统计n!里面有多少个素数5即可。公式:[n/p] + [n/p^2] + [n/p^3] + ……

    然后发现一个很无语的问题,nefu上面不能用这个:

    1 #ifndef ONLINE_JUDGE
    2   freopen("nefu118.in", "r", stdin);
    3 #endif

    要不要这样啊,别的OJ可都是可以用的好不……

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cmath>
     5 using namespace std;
     6 int main(void){
     7   int n, m;
     8   scanf("%d", &m);
     9   while (m--){
    10     scanf("%d", &n);
    11     int t = 5, cnt = 0;
    12     while (t <= n){
    13        cnt += n/t; t *= 5;
    14     }
    15     printf("%d\n", cnt);
    16   }
    17   return 0;
    18 }

    然后,这么个简单的问题,还是纠结了一下……刚开始做数学,加油!

    ↖(^ω^)↗

  • 相关阅读:
    函数的嵌套
    函数对象
    命名关键字参数
    函数part4——函数的参数
    函数part3——函数的返回值
    函数part1——函数的使用原则
    flashback database 基本介绍一
    flash recovery area配置
    根据关键词获取进程ID然后杀掉进程
    rman的conver方法拷贝ASM文件
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/2989959.html
Copyright © 2011-2022 走看看