比赛 |
NOIP2008集训模拟5 |
评测结果 |
AAAAAAAAAA |
题目名称 |
连续素数和 |
最终得分 |
100 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-14 09:02:08 |
显示代码纯文本
program conprime;
const
fin='conprime.in';
fou='conprime.out';
type
node=array[1..100000]of longint;
var
f:array[0..2000,0..2000]of longint;
num,s:array[0..10000]of longint;
b:array[1..10000]of boolean;
a:node;
k,all,x,i,j,n,m:longint;
f1,f2:text;
procedure find;
var
i,j,k,temp:longint;
begin
b[1]:=true;
for i:=2 to m do
begin
if b[i]=false then
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then
begin
b[i]:=true;
break;
end;
k:=2; temp:=i*k;
while temp<=m do
begin
b[temp]:=true;
inc(k);
temp:=i*k;
end;
end;
end;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
readln(f1,x);
while x>0 do
begin
inc(n);
a[n]:=x;
if x>m then m:=x;
readln(f1,x);
end;
find;
for i:=2 to m do
if b[i]=false then
begin
inc(all);
s[all]:=i;
end;
for i:=1 to all do
begin
f[i,i]:=s[i];
num[f[i,i]]:=1;
end;
end;
procedure main;
begin
for k:=2 to all do
for i:=1 to all-k+1 do
begin
j:=i+k-1;
f[i,j]:=f[i,j-1]+f[j,j];
if f[i,j]<=m then inc(num[f[i,j]])
else break;
end;
end;
procedure print;
begin
for i:=1 to n do
writeln(f2,num[a[i]]);
close(f1); close(f2);
end;
begin
init;
main;
print;
end.