Unlucky numbers P27658


Statement
 

pdf   zip

Professor Oak has many quirks. For instance, he thinks that the multiples of 13 are unlucky: 13, 26, 39, 52, …. Moreover, for some reason he also dislikes numbers like 174, “because” its distance to the next century is a (strictly positive) multiple of 13: 200174=26200 - 174 = 26. For the same reason he disaproves numbers like 1061 or 48: 11001061=391100 - 1061 = 39, 10048=52100 - 48 = 52. Note that some numbers like 1287 are doubly disliked: 1287=99131287 = 99 \cdot 13, 13001287=131300 - 1287 = 13.

Given a number nn, can you count how many numbers between 1 and nn are liked?

Input

Input consists of several natural numbers nn, each one between 1 and 101510^{15}.

Output

For every nn, print the quantity of numbers in [1,n][1, n] liked by Professor Oak.

Public test cases
  • Input

    9
    13
    100
    200
    1000000000
    1000000000000000
    

    Output

    8
    11
    86
    171
    858461534
    858461538461534
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++