Number Reduction

시간 제한2초메모리 제한256 MB

요약
1부터 N까지의 정수 중, 자기 자신의 1보다 큰 어떤 자릿수로 나누는 과정을 반복해 1에 도달할 수 있는 수의 개수를 센다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 동적 계획법
정답자
아직 제출이 없습니다

문제

Busy Beaver is given a positive integer kk (1≤k≤10181 \le k \le 10^{18}) written in base 1010. Then, he repeatedly performs the following operation:

Choose a digit in kk that is greater than 11. If kk is divisible by that digit, divide kk by that digit. Repeat this process on the resulting number until either 11 is reached or there are no more legal operations. Call kk valid if there exists a way to reduce it to 11 via this operation.

Compute the number of kk in the range 1,…,N1, \dots, N that are valid.

입력

The first line of input contains the given integer NN (1≤N≤10181 \le N \le 10^{18}).

출력

Output a single line, with a single integer equivalent to the number of integers from 11 to NN that have a way to reach 11 using the operation.

힌트

In the first test case, all integers from 11 to 99 can be divided by themselves to reach 11, so the answer is 99.

In the second test case, all integers from 11 to 99 are valid, as mentioned in the first test case. 1010, 1111, and 1313 have no digits greater than 11 that are divisors of themselves, and therefore cannot be reduced to 11. However, 1212 can be divided by 22 to get 66, which can in turn be divided by 66 to get 11. Therefore, the numbers 11 through 99 and 1212 are valid, giving an answer of 1010.

예제2

  1. 예제 1

    입력
    9
    
    예상 출력
    9
    
  2. 예제 2

    입력
    13
    
    예상 출력
    10