Counting trailing 0s of n! It is not very hard to figure out how to count it - simply count how many 5s. Since even numbers are always more than 5s, we don't have to consider even numbers.

But counting 5, is tricky. Naive method is quite slow - I got 12+s for 1000000000. And after reading below article, I got 0.04s. The former counts individually, duplicated; but the latter counts smart:
http://en.wikipedia.org/wiki/Trailing_zeros#Factorial

#include <iostream>
#include <ctime>
using namespace std; int main()
{
int cnt; cin >> cnt;
if(cnt == ) return ; while(cnt --)
{
unsigned long long n; cin >> n;
unsigned cnt = ; for (int d = ; d <= n; d *= ) {
cnt += n / d;
}
cout << cnt << endl;
}
return ;
}

SPOJ #11 Factorial的更多相关文章

  1. 高性能javascript学习笔记系列(4) -算法和流程控制

    参考高性能javascript for in 循环  使用它可以遍历对象的属性名,但是每次的操作都会搜索实例或者原型的属性 导致使用for in 进行遍历会产生更多的开销 书中提到不要使用for in ...

  2. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  3. SPOJ:Divisors of factorial (hard) (唯一分解&分块优化)

    Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such h ...

  4. 2018.11.24 spoj New Distinct Substrings(后缀数组)

    传送门 双倍经验(弱化版本) 考虑求出来heightheightheight数组之后用增量法. 也就是考虑每增加一个heightheightheight对答案产生的贡献. 算出来是∑∣S∣−heigh ...

  5. 2018.11.18 spoj Triple Sums(容斥原理+fft)

    传送门 这次fftfftfft乱搞居然没有被卡常? 题目简述:给你nnn个数,每三个数ai,aj,ak(i<j<k)a_i,a_j,a_k(i<j<k)ai​,aj​,ak​( ...

  6. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  7. [codeforces 516]A. Drazil and Factorial

    [codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define  ...

  8. SPOJ #440. The Turtle´s Shortest Path

    Coding a Dijkstra is not hard. %70 of my time spent on tackling TLE, as my last post. Dijkstra works ...

  9. SPOJ #2 Prime Generator

    My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceede ...

随机推荐

  1. mark资料-python编辑器的选择与安装

    1.pycharm 下载地址: 注册码: 注意事项: 2.ulipad参考虫师的地址 url: 3.eclipse+pydev

  2. LK 光流法简介

    前言 若假定一个局部区域的像素运动是一致的,则可以用这个新的约束条件替代前文中提到的全局速度平滑约束条件.这种光流算法就叫做 LK 光流法. LK 光流法的推导 首先,需要推导出光流约束方程. 这一步 ...

  3. Java-->用递归方法复制目录、子目录以及文件(文件用到IO流)

    package com.dragon.java.newcopyfile; import java.io.File; import java.io.FileInputStream; import jav ...

  4. 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

    odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. Matlab神经网络工具箱学习之二

    螃蟹的分类 这个例子的目的是根据螃蟹的品种.背壳的长宽等等属性来判断螃蟹的性别,雄性还是雌性. 训练数据一共有六个属性: species, frontallip, rearwidth, length, ...

  6. [JSP] c:forEach 输出序号 每行自动生成序号

    关键在于<c:forEach>的varStatus属性,具体代码如下: <table width="500" border="0" cells ...

  7. MATLAB格式化输出控制 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏

    MATLAB格式化输出控制 format 默认格式 format short 5字长定点数 format long 15字长定点数 format short e 5字长浮点数 format long ...

  8. html---文本框样式;

    一.一个单行文本框的例子 <form name="form1" action="mailto:3400982550@qq.com" method=&quo ...

  9. JavaWeb学习记录(五)——Servlet随机产生验证码

    随机产生验证码的工具类: import java.awt.Color;import java.awt.Graphics;import java.awt.image.BufferedImage;impo ...

  10. C 语言中 free() 函数简单分析

    又是一个睡不着的夜晚,现在是凌晨03:16,不知道是不是感冒的原因,头脑并不是清醒,但是就是睡不着.摸着黑打开电脑,洗了杯子抓了点茶叶,然后打开饮水机电源.舍友们都睡着了,我戴着耳机听着轻音乐,也能听 ...