ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1091. Tmutarakan Exams

i really don't know why it got WA, need help please!
Posted by BShell 14 Apr 2003 12:16
var ans:longint;
num,i,k,s,x:longint;

function c(m,n:longint):longint;
var ans:int64;
i:longint;
begin
ans:=1;
for i:=1 to m do
ans:=ans*(n+1-i);
for i:=1 to m do
ans:=ans div i;
c:=ans;
end;

function divide(x:longint):longint;
var i,tot:longint;
begin
i:=1;
tot:=0;
repeat
inc(i);
if x mod i=0 then
begin
x:=x div i;
if x mod i=0 then
begin
divide:=0;
exit;
end;
inc(tot);
end;
until x=1;
divide:=tot;
end;

begin
ans:=0;
for i:=2 to s do
if (s div i>=k) then
begin
x:=s div i;
num:=divide(i);
if num<>0 then
begin
if num mod 2=1 then
inc(ans,c(k,x))
else dec(ans,c(k,x));
end;
end;
if ans>10000 then ans:=10000;
writeln(ans);
end.