2 条题解

  • 0
    @ 2025-11-23 20:12:41

    #include<bits/stdc++.h> using namespace std;

    int main(){ int n; while(cin>>n){ int ans=0; for(int i=1;i<=n;i++){ int m=i; while(m%5==0){ ans++; m/=5; } } cout<<ans<<endl; } return 0; }

    理清,末尾零的个数就是因数5的个数

    • 0
      @ 2024-12-24 9:49:25

      C :

      #include <stdio.h>
      #include <math.h>
      
      int main()  
      {  
      	int n; 
          while(scanf("%d",&n)!=EOF)  
          {  
              int sum=0;  
              while(n>=5)  
              {  
                  n/=5;
                  sum+=n; 
             }  
      	   printf("%d\n",sum);  
          }  
          return 0;  
            
      }  
      
      
      
      

      C++ :

      #include<stdio.h>
      int main()
      {
      	int a=0,b=0,i,j;
      	while(~scanf("%d",&a))
      	{
      		for(i=1 ;i<=a;i++)
      		{
      			j=i;
      			while(j%5==0)
      			{
      				b++;
      				j/=5;
      			}
      
      		}
      		printf("%d\n",b);
      		b=0;
      		
      	}
      	return 0;
      }
      
      
      
      • 1

      信息

      ID
      963
      时间
      1000ms
      内存
      128MiB
      难度
      10
      标签
      (无)
      递交数
      2
      已通过
      3
      上传者