Under construction

Still being built. Things may change

The Easiest Problem Is This One

Time limit1sMemory limit128 MB

Summary
For each positive integer N up to 100000, find the smallest multiplier p greater than 10 such that N and N*p have the same decimal digit sum.
Level

Easy3 of 10

Topics
Brute force, Math, Implementation, Number theory
Solved
No attempts yet

Problem

Write a positive integer NN in the decimal system as a sequence of digits.

N=d1d2d3…dk,0≤di≤9.N = d_1 d_2 d_3 \dots d_k, \qquad 0 \le d_i \le 9.

Each digit contributes a value multiplied by a power of 1010.

N=d1⋅10k−1+d2⋅10k−2+⋯+dk−1⋅10+dk=∑i=0k−1di+1⋅10k−i−1.N = d_1 \cdot 10^{k-1} + d_2 \cdot 10^{k-2} + \dots + d_{k-1} \cdot 10 + d_k = \sum_{i=0}^{k-1} d_{i+1} \cdot 10^{k-i-1}.

The digit sum S(N)S(N) is the plain sum of the digits, without multiplying by any power of 1010.

S(N)=d1+d2+⋯+dk=∑i=0k−1di+1.S(N) = d_1 + d_2 + \dots + d_k = \sum_{i=0}^{k-1} d_{i+1}.

For example, if N=3029N = 3029 then S(N)=3+0+2+9=14S(N) = 3 + 0 + 2 + 9 = 14.

Multiplying NN by another number usually changes the digit sum. For example, with m1=26m_1 = 26:

N⋅m1=78754,S(N⋅m1)=7+8+7+5+4=31.N \cdot m_1 = 78754, \qquad S(N \cdot m_1) = 7 + 8 + 7 + 5 + 4 = 31.

However, some multipliers leave the digit sum unchanged. For example, with m2=37m_2 = 37:

N⋅m2=112073,S(N⋅m2)=1+1+2+0+7+3=14=S(N).N \cdot m_2 = 112073, \qquad S(N \cdot m_2) = 1 + 1 + 2 + 0 + 7 + 3 = 14 = S(N).

Find the smallest positive integer pp that is greater than 1010 and satisfies S(N)=S(N⋅p)S(N) = S(N \cdot p).

Input

The input consists of several test cases. Each test case is a single line containing one positive integer NN, where 1≤N≤100 0001 \le N \le 100\,000. The last test case is followed by a line containing a single 00, which is not processed.

Output

For each test case, print on its own line the smallest integer pp greater than 1010 for which S(N)=S(N⋅p)S(N) = S(N \cdot p).

Examples3

  1. Example 1

    Input
    3029
    4
    5
    42
    0
    
    Expected output
    37
    28
    28
    25
    
  2. Example 2

    Input
    9
    0
    
    Expected output
    12
    
  3. Example 3

    Input
    7
    11
    99
    100
    0
    
    Expected output
    19
    91
    11
    100