fork download
  1. program enigmath;
  2. Uses Math;
  3. const MAXX=102;
  4. var
  5. Emin, Emax, i, S, K, inizio, val : longint;
  6. cod, dec :array[1..100000000] of longint;
  7.  
  8. function codifica (x:Longint):Longint;
  9. begin
  10. if x < 10 then codifica:=x (* single digit*)
  11. else
  12. begin
  13. S := 0; K:= x;
  14. while K>0 do
  15. begin
  16. S:=S + K mod 10; (*sum of digits*)
  17. K:=K div 10;
  18. end;
  19. codifica:=x + codifica(S);
  20. end;
  21. end;
  22.  
  23. begin
  24. (*assign(input, 'input.txt'); reset(input);
  25.   assign(output, 'output.txt'); rewrite(output);*)
  26.  
  27. readln(Emin,Emax);
  28. if Emin<=102 then inizio:=0
  29. else inizio:=Emin-102;
  30. for i:=inizio to Emax do dec[i]:=0;
  31. for i := inizio to Emax do
  32. begin
  33. val := codifica(i);
  34. if (Emin <= val) and (val <= Emax) then
  35. begin
  36. cod[val]:=i;
  37. dec[val]:=dec[val]+1;
  38. end;
  39. end;
  40. for i := Emin to Emax do
  41. begin
  42. if dec[i]= 0 then writeln('IMPOSSIBLE')
  43. else if dec[i]>1 then writeln('AMBIGUOUS')
  44. else writeln(cod[i]);
  45. end;
  46. end.
Success #stdin #stdout 0s 5288KB
stdin
107 107
stdout
103