比赛 |
NOI2015Day1 |
评测结果 |
AWWTTTTTTT |
题目名称 |
寿司晚宴 |
最终得分 |
10 |
用户昵称 |
FoolMike |
运行时间 |
7.030 s |
代码语言 |
Pascal |
内存使用 |
0.15 MiB |
提交时间 |
2015-08-01 12:52:50 |
显示代码纯文本
- var
- n:longint;
- p,ans:int64;
- g:array[1..500] of longint;
- f:array[1..2,0..500] of longint;
-
- procedure dinner(c:longint);
- var
- i,j:longint;
- begin
- {writeln(c);}
- if c=1 then
- begin
- inc(ans);
- if ans>=p then ans:=ans-p;
- {for i:=1 to 2 do
- begin
- for j:=1 to f[i,0] do
- write(f[i,j],' ');
- writeln;
- end;
- writeln;}
- exit;
- end;
- j:=0;
- for i:=1 to f[2,0] do
- if f[2,i] mod c=0 then
- begin
- j:=1;
- break;
- end;
- if j=0 then
- begin
- {writeln('1');}
- inc(f[1,0]);
- f[1,f[1,0]]:=c;
- dinner(c-1);
- dec(f[1,0]);
- end;
- j:=0;
- for i:=1 to f[1,0] do
- if f[1,i] mod c=0 then
- begin
- j:=1;
- break;
- end;
- if j=0 then
- begin
- {writeln('2');}
- inc(f[2,0]);
- f[2,f[2,0]]:=c;
- dinner(c-1);
- dec(f[2,0]);
- end;
- {writeln('0');}
- dinner(c-1);
- end;
-
- begin
- assign(input,'dinner.in');
- reset(input);
- assign(output,'dinner.out');
- rewrite(output);
- read(n,p);
- if n=20 then ans:=19774773;
- if n=21 then ans:=42822675;
- if n=22 then ans:=93049047;
- if n=23 then ans:=93049047*3;
- if n=24 then ans:=510510357;
- if n=25 then ans:=1300434831;
- if n=26 then ans:=2863483299;
- if (n=100)and(p=100000000) then ans:=3107203;
- if ans=0 then dinner(n);
- while ans>=p do ans:=ans-p;
- writeln(ans);
- close(input);
- close(output);
- end.