Блог пользователя Vasiljko

Автор Vasiljko, история, 9 лет назад, По-английски

List of integers is formed such that all integers that can be written in form 2x3y5z are sorted in increasing order. So, list look like this: 1, 2, 3, 4, 5, 6, 8, 9, ... What is n-th element (0-indexed) in list?
0 <  = n <  = 105

Input
500
Output
944784

  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Am I missing anything, or answer for 500 is 937500?

»
9 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +16 Проголосовать: не нравится

Disregarding the overflow, I think this should work: create an ordered set which contains the element 1 initially. Now, you will do the following n + 1 times: pop out the smallest element X in the set (and delete it) and then put the elements 2X, 3X and 5X in the set. The n + 1-th popped element is the answer.