jz1196:【基础】圆环上求素数

 

 

//思路和代码由温州瓦市小学5年级同学郑承寅提供

var
    n,i,c,x:longint;
    s:string;
function prime(a:longint):boolean;
var i:longint;
begin
    if a<2 then exit(false);
    for i:=2 to trunc(sqrt(a)) do
        if a mod i=0 then exit(false);
    exit(true);
end;
begin
    readln(n);
    s:='12345678901234567890';
    c:=1;
    for i:=1 to 9 do
    begin
        val(copy(s,i,n),x);
        if prime(x) then
        begin
            if c>1 then write(',');
            inc(c);
            write(x);
        end;
    end;
    writeln; 
end.

 

posted @ 2014-11-29 19:58  qilinart  阅读(624)  评论(0编辑  收藏  举报