ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1071. Nikifor 2

Help me!!!!!!!! why 6 test wrong answer????????
Posted by Виктор Крупко 31 Mar 2005 00:23
program de;
   var
   a,n,i,r,x,y,step,j:longint;
   q:boolean;
   s1,s2,s:string;
begin
  step:=1;
  q:=false;
  read(x);
  read(y);
  repeat
  s1:='';
  s2:='';
  n:=x;
  inc(step);
  repeat
  i:=n mod step;
  n:=n div step;
  str(i,s);
  s1:=s+s1;
  until n=0;
  r:=y;
  repeat
  i:=r mod step;
  r:=r div step;
  str(i,s);
  s2:=s+s2;
  until r=0;
  j:=1;
  for i:=1 to length(s1) do
  if (s1[i]=s2[j]) and (j<>length(s2)+1) then inc(j);
  if j=length(s2)+1 then q:=true;
  until (step=x+1) or q;
  if q then writeln(step)
  else writeln('No solution');
end.