SGU 231 — Prime Sum
只说一点:如果一个素数p是两个素数a和b的加和,那么a和b一定有且仅有一个为2…正确性显然…
筛法还是蛮快的.
{
SGU 231; Prime Sum
- sqybi’s code
}
//for my winsty
program sgu231_sqybi;
var
n, i, j, s: longint;
p: array[1..1000000]of boolean;
begin
readln(n);
fillchar(p, sizeof(p), true);
for i:=2 to n do
if p[i] then
for j:=2 to n div i do
p[i*j] := false;
s := 0;
for i:=2 to n-2 do
if p[i] and p[i+2] then
inc(s);
writeln(s);
for i:=2 to n-2 do
if p[i] and p[i+2] then
writeln(2, ‘ ‘, i);
end.
阅读(62 次)
强调 筛法复杂度貌似是 O(nlnlnlnn) -.-
_gXX
五月 11th, 2008
神奇的东西=.=
sqybi
五月 12th, 2008