var n, k, s: integer; a: array of integer; function IsPrime(n: integer): boolean; var i: integer; begin if n <= 1 then Exit(False) else if n <= 3 then Exit(True) else if (n mod 2 = 0) or (n mod 3 = 0) then Exit(False); i := 5; while (i * i) <= n do begin if (n mod i = 0) or (n mod (i + 2) = 0) then Exit(False); i := i + 6; end; Exit(True); end; begin s := 0; write('n = '); readln(n); SetLength(a, n); for k := 0 to (n - 1) do begin write('a[', k, '] = '); readln(a[k]); if IsPrime(k) then s := s + a[k]; end; writeln('ответ: ', s); end.
var
n, k, s: integer;
a: array of integer;
function IsPrime(n: integer): boolean;
var
i: integer;
begin
if n <= 1 then
Exit(False)
else
if n <= 3 then
Exit(True)
else
if (n mod 2 = 0) or (n mod 3 = 0) then
Exit(False);
i := 5;
while (i * i) <= n do
begin
if (n mod i = 0) or (n mod (i + 2) = 0) then
Exit(False);
i := i + 6;
end;
Exit(True);
end;
begin
s := 0;
write('n = ');
readln(n);
SetLength(a, n);
for k := 0 to (n - 1) do
begin
write('a[', k, '] = ');
readln(a[k]);
if IsPrime(k) then
s := s + a[k];
end;
writeln('ответ: ', s);
end.