#8824: 用什么办法不逾时


lswei (魏子轩)


要PASCAL的
#8831: Re:用什么办法不逾时


lswei (魏子轩)


要PASCAL的



var
  a:array[0..10,1..1000000] of boolean;
  b,c,d,e,i,j,s,z:longint;
begin
  s:=0;
  z:=1;
  for e:=2 to 1073741823 do begin
   i:=e*2-1;
   for j:=2 to trunc(sqrt(i)) do begin
    z:=i;
    while i>1000000 do begin
     z:=i-1000000;
     s:=s+1;
    end;
    a[s,z]:=true;
    if i mod j=0 then begin a[s,z]:=false; break; end;
   end;
  end;
  while not eof do begin
   readln(b);
   d:=0;
   while b>1000000 do begin
    c:=b-1000000;
    d:=d+1;
   end;
   if b=1 then writeln('非質數')
          else if b=2 then writeln('質數')
                      else if a[d,c]=true then writeln('質數')
                                          else writeln('非質數');
   readln(b);
  end;
end.

 这是我的代码,请帮忙看看

#8833: Re:用什么办法不逾时


yishabeier (gzy)


呵呵

#9038: Re:用什么办法不逾时


fantasy_whale (幻光海鯨)


我用費馬小定理過的,很麻煩

我想有機會貼一下文章 

#9039: Re:用什么办法不逾时


fantasy_whale (幻光海鯨)


我用費馬小定理過的,很麻煩

我想有機會貼一下文章 

#9132: Re:用什么办法不逾时


tonytonyjan (南洋大兜蟲)


What about Miller–Rabin?
#9133: Re:用什么办法不逾时


tonytonyjan (南洋大兜蟲)


What about Miller–Rabin?
#9134: Re:用什么办法不逾时


tonytonyjan (南洋大兜蟲)


我用費馬小定理過的,很麻煩

我想有機會貼一下文章 


What about Miller–Rabin?
#9135: Re:用什么办法不逾时


tonytonyjan (南洋大兜蟲)


Miller–Rabin