码迷,mamicode.com
首页 > 其他好文 > 详细

172 Factorial Trailing Zeroes 过了。英文真不好读啊。

时间:2014-12-30 19:05:36      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

package com.x.xyz;

public class HelloWorld {

	public static void main(String[] args) {
		System.out.println("Star !");
		System.out.println(trailingZeroes(10));
		System.out.println(trailingZeroes(125));
		System.out.println(trailingZeroes(25));
		System.out.println(trailingZeroes(3));
		System.out.println(trailingZeroes(4));
		System.out.println(trailingZeroes(5));
		System.out.println(trailingZeroes(6));
		System.out.println(trailingZeroes(7));
	}
	
	public static int trailingZeroes(int n) {
		int x = 5;
		int ans = 0;
		while(n >= x) {
			ans = ans + n/x;
			x = x*5;
		}
		return ans;
	}
}

172 Factorial Trailing Zeroes 过了。英文真不好读啊。

标签:

原文地址:http://blog.csdn.net/wide288/article/details/42270101

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!