#P3464. Integers’ Weight

    ID: 2348 远端评测题 1000ms 64MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2010 ACM-ICPC Multi-University Training Contest(3)——Host by WHU

Integers’ Weight

Problem Description

The weight of a positive integer is the sum of its digits. For example, weight(12097) = 1+2+0+9+7 = 19. For any positive integer x, f(x) = 1 if weight(x) = x, and f(x) = f(weight(x))+1 otherwise. For example, f(2) = 1 and f(654) = f(15)+1 = f(6)+1+1 = 3.
Find the smallest number x that f(x) = n. The answer may be huge, just output the remainder after divided by 100007.

Input

There are several test cases in the input.

Each test case begin with an integer n (1 <= n <= 1000000000).

The input terminates by end of file marker.

Output

For each test case, output the result in a single line.

2 3
10 19

Author

hanshuai