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 1055. Combinations

why my program is wrong?
Posted by wangchun 19 Jul 2003 14:33
const max=5200;
var zs:array[1..max]of longint;
    sz:array[1..max]of longint;
    num,n,m,out:longint;
procedure add(k:longint);
var t:longint;
begin
     for t:=1 to num do
         begin
              if k mod zs[t]=0 then
                 begin
                      k:=k div zs[t];
                      inc(sz[t]);
                 end;
              if k=1 then
                 break;
         end;
end;
procedure minus(k:longint);
var t:longint;
begin
     for t:=1 to num do
         begin
         if k mod zs[t]=0 then
            begin
                 k:=k div zs[t];
                 dec(sz[t]);
            end;
         if k=1 then
            break;
         end;
end;
procedure init;
var t,k:longint;
    q:boolean;
begin
     num:=0;
     fillchar(zs,sizeof(zs),0);
     fillchar(sz,sizeof(sz),0);
     readln(n,m);
     for t:=2 to 50000 do
         begin
              q:=true;
              for k:=2 to trunc(sqrt(t)) do
                  if t mod k=0 then
                     begin
                          q:=false;
                          break;
                     end;
              if q then
                 begin
                      inc(num);
                      zs[num]:=t;
                 end;
         end;
     for t:=n downto m+1 do
         add(t);
     for t:=2 to n-m do
         minus(t);
end;
procedure make;
var t:integer;
begin
     out:=0;
     for t:=1 to num do
         if sz[t]>0 then
            inc(out);
end;
procedure print;
begin
     writeln(out);
end;
begin
     init;
     make;
     print;
end.