[0716] Jsoi B Rsss
rsss
時間限制:1秒??內存限制: 128 MB
試題描述
????在質數的大家庭中,大小之差不超過2的兩個質數稱它倆為一對孿生素數,如2和3、3和5、17和19等等。請你統計一下,在不大于自然數N的質數中,孿生素數的對數。
輸入要求
????輸入文件rsss.in只有一行,一個自然數N。(N<=10^6)
輸出要求
????輸出文件rsss.out只有一行,一個整數,表示N以內孿生素數的對數。
輸入樣例
20
輸出樣例
5
知識點及提示
打印素數表的方法0.0
?
Var i,j,n,l,k:longint;
??? p:array[1..1000000]of boolean;
??? pt:Array[1..100000]of longint;
function pr(l:longint):boolean;
var kk:longint;
begin
? for kk:=1 to trunc(sqrt(l)) do if (l mod i=0) and (l<>kk) then exit(true);
? exit(false);
end;
begin
? fillchar(p,sizeof(p),true);
? i:=2;
? readln(n);
? i:=2;
? while i<=n do
? begin
??????? if p[i] then
??????? begin
??????? j:=i*2;
??????? while j<=n do
??????? begin p[j]:=false; inc(j,i); end;
??????? end;
??????? inc(I);
? end;
? l:=0;
? for i:=1 to n do if p[i] then
? begin
??? inc(l);
??? pt[l]:=i;
? end;
? if not pr(n) then begin
??? inc(l);
??? pt[l]:=n;
? end;
? for i:=2 to? l do if (pt[i+1]-pt[i]<=2)and (pt[i+1]<>0) and(pt[i]<>0) then? inc(k);
? writeln(k);
end.
?
轉載于:https://www.cnblogs.com/shy-/archive/2012/07/16/2593263.html
總結
以上是生活随笔為你收集整理的[0716] Jsoi B Rsss的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编写atoi库函数
- 下一篇: “软件工程造价师”和“软件造价评估师”有