主题:1000!尾0问题
			
 xxwygj
				 [专家分:0]  发布于 2005-08-10 13:22:00							
			[em18]大哥大姐,请快来帮帮我,
 急急……
 谢谢!
 提示: 1000!=1*2*3*……*1000
 问:1000!的末尾有多少个“0”?
						
					 
		
			
回复列表 (共24个回复)
		
								
				11 楼
				
					
killercat [专家分:1330]  发布于 2005-08-25 00:54:00				
				
#include <stdio.h>
int main()
{
    long n,m;
    long num;
    while((scanf("%ld",&n))!=EOF){
        num=0;
        while(n>0){
            m=n;
            while(m%5==0){
                num++;
                m/=5;
            }
            n--;
        }
        printf("%ld\n",num);        
    }
    return 0;
}
							 
						
				12 楼
				
					
snowwhite [专家分:1050]  发布于 2005-08-25 14:48:00				
				#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    long n = 1000;
    int s = 0;
    while( ( n = n / 5 ) > 0 )
        s += n;
    cout << s;
    getch();
    return 0;
}
        
							 
						
				13 楼
				
					
snowwhite [专家分:1050]  发布于 2005-08-25 14:49:00				
				#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    long n = 1000;
    int s = 0;
    while( ( n = n / 5 ) > 0 )
        s += n;
    cout << s;
    getch();
    return 0;
}
        
							 
						
				14 楼
				
					
hadewood [专家分:60]  发布于 2005-08-27 14:51:00				
				有什么难的吗?
好好学数学去
trunc(1000/4)-1
							 
						
				15 楼
				
					
yyw57156 [专家分:100]  发布于 2005-09-18 12:11:00				
				每次乘以下一个数后 为a
  if a mod 10 <>0 then
    a:=a mod 10
							 
						
				16 楼
				
					
yyw57156 [专家分:100]  发布于 2005-09-18 12:13:00				
				for i:=1 to 1000 do begin
  begin
     s:=s+i;
     if s mod 10 <>0 then s:=s mod 10
     else s:=s div 10
  end
							 
						
				17 楼
				
					
yyw57156 [专家分:100]  发布于 2005-09-18 12:17:00				
				不好意思我看错题目了
							 
						
				18 楼
				
					
maleo [专家分:510]  发布于 2005-10-05 18:11:00				
				我的算法:
找出能被5整除的+,与偶数相乘有1个0
能被25整除的+2,              2个0
能被125整除的+3               3个0
能被625整除的+4               4个0
注意以上的数只能同时满足一个,否则就重复计算了,最后的结果是249个
#include <stdio.h>
#include <stdlib.h>
void main()
{
    int i = 1 , count = 0 ;
    for( i = 1  ; i <= 1000 ; i++  )
    {
        if( i%625 == 0 )
        {
            count += 4 ;
            printf("%d ",i) ;
        }
        else if(  i % 125 == 0 )
        {
            if( i%625 == 0 )
            {
                continue ;
            }
            else
            {
                count += 3 ;
            }
        }
        else if( i % 25 == 0 )
        {
            if(( i%125 == 0 )||( i%625==0 ))
            {
                continue ;
            }
            else
            {
                count += 2 ;
            }
        }
        else if( i % 5 == 0 )
        {
            if(( i%125 == 0 )||( i%625==0 )||( i%25 == 0 ))
            {
                continue ;
            }
            else
            {
                count ++ ;
            }
        }
    }
    printf("%d",count) ;
    getch() ;
}
							 
						
				19 楼
				
					
格子裙 [专家分:15760]  发布于 2005-10-11 01:45:00				
				http://www.programfan.com/blog/article.asp?id=3581
							 
						
				20 楼
				
					
157502970 [专家分:190]  发布于 2005-10-12 20:13:00				
				好象是
#include <iostream.h>
main()
{
    long n,i;
    while(cin>>n)
    {
        i=(n-(n%5))/5+(n-(n%25))/25+(n-(n%125))/125+(n-(n%625))/625+
        (n-(n%3125))/3125+(n-(n%15625))/15625+(n-(n%78125))/78125+
        (n-(n%390625))/390625;
        cout<<i<<"\n";
    }
}
							 
									
			
我来回复