CF633 B 数论 阶乘末尾有几个0 二分

13 篇文章 0 订阅
http://codeforces.com/contest/633/problem/B
B. A Trivial Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?

Input

The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.

Output

First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.

Examples
input
1
output
5
5 6 7 8 9 
input
5
output
0
Note

The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.

In the first sample, 5! = 1206! = 7207! = 50408! = 40320 and 9! = 362880.

额,每次都能遇到一些新的知识点。可喜可贺可喜可贺......

题目大意:就是一个阶乘中有几个0。

首先思考一下,因为在一个数字中,2作为因子的次数肯定比5多。那么就只需要考虑5出现过几次就可以了。然后就是解释一下为什么25的时候是6个0,因为25中有两个5,所以一共就有6个0。

来一个例子

从1到10,连续10个整数相乘:
从1×2×3×4×5×6×7×8×9×10中可以得出其中5的因数有2个,所以它们的乘积末尾有2个0
从1到20,20个整数相乘:从中可以得出其中5的因数有4个,所以它们的乘积末尾有4个0
从1到30,30个整数相乘:从中可以得出其中5的因数有5,但25中有2个5,所以一共是6个,所以它们的乘积末尾有6个0

#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
       
        
        
#include
        
        
          #include 
         
           #include 
           #include 
           
             #include 
            
              using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; int m; int cal(int x){ int cnt = 0; while (x){ x /= 5; cnt += x; } return cnt; } int main(){ while (scanf("%d", &m) == 1){ int lb = 0, ub = inf; while (ub > lb){ int mid = (ub - lb) / 2 + lb; int t = cal(mid); if (t >= m) ub = mid; else lb = mid + 1; } //printf("lb = %d\n", lb); vector 
             
               a; while (cal(lb) == m){ a.push_back(lb); lb++; } int lo = a.size(); printf("%d\n", lo); for (int i = 0; i < lo; i++){ printf("%d%c", a[i], i == lo-1? '\n':' '); } } return 0; } 
              
             
            
          
        
       
       
      
      
     
     
    
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值