SGU 231 — Prime Sum

Posted on 五月 11th, 2008.

只说一点:如果一个素数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 次)

Make a Comment

Make A Comment: ( 2 so far )

blockquote and a tags work here.

2 Responses to “SGU 231 — Prime Sum”

RSS Feed for NOT A BLOG | sqybi Comments RSS Feed

强调 筛法复杂度貌似是 O(nlnlnlnn) -.-

_gXX
五月 11th, 2008

神奇的东西=.=

sqybi
五月 12th, 2008

Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...