[BOJ 7111] The Strange Sequence

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 128M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

There is a sequence of positive integers {ai}. For each i (i>1) ai is the least possible integer with the following features:</p>

  1. ai > ai-1,
  2. the sum of ai digits equals the sum of 4 * ai-1 digits.

For the given values of the first sequence member a1 and the index n, you must find and output the value of the an.

입력 형식

The values of integers a1 (0 < a1 < 20) and n (0 < n < 10000) are input from the keyboard.

출력 형식

You must write one integer on the screen - the value of the an. For the testing, only data where the corresponding an value does not increase 109 are to be used.

예제 입력

4 5

예제 출력

79

Comments

There are no comments at the moment.