讨论 / ……
Ulquiorra 2013-07-10 19:53:00
点我顶贴 收藏 删除
program project1;

const max=5000;

var n,m,i,j,sum,ans:longint;

a:array[0..1000000]of longint;

v:array[0..1000000]of boolean;

f:boolean;

//==============================================================================

procedure mult(x:longint);

var r:longint;

begin

a[1]:=a[1]*x;

for r:=2 to ans do

begin

a[r]:=a[r]*x;

a[r]:=a[r]+(a[r-1] div 10);

a[r-1]:=a[r-1]mod 10;

end;

while a[ans]>=10 do

begin

inc(ans);

a[ans]:=a[ans-1] div 10;

a[ans-1]:=a[ans-1] mod 10;

end;

end;

//------------------------------------------------------------------------------

procedure work(x:longint);

var p,k1,k2,k3,t:longint;

begin

k1:=0;k2:=0;k3:=0;

p:=x;

while p<=(m+n) do

begin

k1:=k1+(m+n) div p;

p:=p*x;

end;

p:=x;

while p<=(m+1) do

begin

k2:=k2+(m+1) div p;

p:=p*x;

end;

p:=x;

while p<=n do

begin

k3:=k3+n div p;

p:=p*x;

end;

k1:=k1-k2-k3;

if k1>0 then

for t:=1 to k1 do mult(x);

if k1<0 then f:=false;

end;

//==============================================================================

begin

assign(input,'stick.in');

assign(output,'stick.out');

reset(input);

rewrite(output);

fillchar(v,sizeof(v),true);

f:=true;

readln(m,n);

if n>m then

begin

writeln('0');

close(input);

close(output);

halt;

end;

a[1]:=1; ans:=1;

i:=2;

while i*i<=max*2 do

begin

j:=i*2;

while j<=max*2 do

begin

v[j]:=false;

j:=j+i;

end;

i:=i+1;

end;

sum:=0;

for i:=2 to m+n do

if v[i] then work(i);

if f then mult(m-n+1);

for i:=ans downto 1 do write(a[i]);

writeln;

close(input);

close(output);

end.

查看更多回复
提交回复