TopCoder problem "ReverseMagicalSource" used in SRM 451 (Division II Level One)



Problem Statement

    Rick firmly believes that there are magical patterns related to some numbers. This belief is the result of his own tendency to find odd patterns everywhere. He has recently thought that some numbers have a "magical source". For example, the number 1370974 has a magical source equal to 1234 because of the following process:

     1234
+   12340
+  123400
+ 1234000
---------
  1370974
Formally, 1234 is a magical source of 1370974 because there exists a number n such that the sum of a sequence of n numbers, where the i-th number (0-indexed) is 1234 multipled by 10^i, is equal to 1370974. Note that by this definition, a positive number is a magical source of itself.



Given a positive int source, and an int A return the minimum number x such that x is greater than A and source is a magical source of x.
 

Definition

    
Class:ReverseMagicalSource
Method:find
Parameters:int, int
Returns:int
Method signature:int find(int source, int A)
(be sure your method is public)
    
 

Constraints

-source will be between 1 and 1000000, inclusive.
-A will be between 1 and 1000000, inclusive.
 

Examples

0)
    
19
200
Returns: 209
19 + 190 = 209
1)
    
19
18
Returns: 19
A positive number is a magical source of itself.
2)
    
333
36963
Returns: 369963
3)
    
1234
1000000
Returns: 1370974

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10674

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13905&pm=10674

Writer:

vexorian

Testers:

PabloGilberto , bmerry , ivan_metelsky

Problem categories:

Simple Search, Iteration