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 1057. Amount of Degrees

Why WA6
Posted by Rabidstorm 5 Aug 2009 13:18
This is my program:
program Ural1057;

var
  a,l,r,n,k,ans:longint;
  p:array[0..200]of longint;
  d:array[0..200]of qword;
  num:qword;

procedure dfs(o:longint);

var
  i:longint;

begin
  for i:=p[o-1]+1 to 30 do
    begin
      p[o]:=i;
      num:=num+d[p[o]];
      if num>r then
      begin
        num:=num-d[p[o]];
        exit;
      end;
      if o=n then begin
        if l<=num then inc(ans);
      end else
      dfs(o+1);
      num:=num-d[p[o]];
    end;
end;

begin
  readln(l,r,n,k);
  fillchar(p,sizeof(p),0);
  d[0]:=1;
  a:=1;
  while (d[a-1]<r)and(a<40) do
    begin
      d[a]:=d[a-1]*k;
      inc(a);
    end;
  ans:=0;
  num:=0;
  p[0]:=-1;
  dfs(1);
  writeln(ans);
end.

I don't know why Wa6, who can help me?