The Strange Sequence
Time limit1sMemory limit128 MB
Given a start value and index n, build the sequence where each next term is the smallest number greater than the previous one whose digit sum equals the digit sum of four times the previous term, then print the n-th term.
- Level
Medium6 of 10
- Topics
- Implementation, Math, Greedy, Simulation
- Solved
- No attempts yet
Problem
Consider a sequence of positive integers . The first term is given. For every , the term is the smallest integer that satisfies both of the following conditions:
- ;
- the digit sum of equals the digit sum of .
Given the first term and an index , output the value of .
Input
A single line contains two integers and separated by a space (, ).
Output
Print a single integer: the value of . All test data are chosen so that does not exceed .