how many does the factorial of n(in binary data ) have zero?
个人信息:就读于燕大本科软件工程专业 目前大三;
本人博客:google搜索“cqs_2012”即可;
个人爱好:酷爱数据结构和算法,希望将来从事算法工作为人民作出自己的贡献;
博客内容:how many does the factorial of n have zero?
博客时间:2014-5-6;
编程语言:Java ;
编程坏境:Windows 7 专业版 x64;
编程工具:jdk,eclipse x64;
制图工具:office 2010 ppt;
硬件信息:7G-3 笔记本;
my words
problem( from beauty of programming )Attitude beats all.
my solutionhow many does the factorial of n(in binary data ) have zero?
eg: n = 5;
n! = 1 * 2 * 3 * 4 * 5 = 120 = 0111 1000 ;
the right result is 3.
experimentsas for n!, the time that n! can divided by 2 without reminder is the result.
my code
program note:
for every row
first number: n
second number: the result the problem require
test.java
package test; public class test { public static void main(String[] args) { int i =0; while(i < 100) System.out.println(i+" "+_zero_number_with_binary(i++)); } static int _zero_number_with_binary(int n) { int result = 0; int i = n ; while(i>0) { result += i/2 ; i = i/2 ; } return result; } }