how many does the factorial of n(in binary data ) have zero?

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

Attitude beats all.

problem( from beauty of programming )

how 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.

my solution 

as for n!, the time that n! can divided by 2 without reminder is the result.


experiments


program note:

for every row 

first number: n

second number: the result the problem require

my code

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;
	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值