10000までの素数を求めます。
int fscroll=YES:// YES=scroll(V2.00以降専用) / NO=page
if isLocalizeJapan() then {
print "エラトステネスのふるい(〜10000)"
} else {
print "Sieve of Eratosthenes(to 10000)"
}
print "start:";time$
//
int i,p
int max=10000
dim nt(10000):/* 確保時の初期値は0=NO
for i=2 to max/2
nt(i*2)=YES
next
p=3
while p*p<=max
for i=p to max/p
nt(i*p)=YES
i=i+1:/* step2
next
p=p+1
while nt(p):p=p+1:endwhile
endwhile
int cnt=0
for i=2 to max
if nt(i)=0 then {
print i,
if not fscroll then {
inc(cnt)
if cnt>=30*8 then {
// スクロールできないので一定数ごとに画面クリアして継続
hitKey()
cls()
cnt=0
}
}
}
next
print
print "end:";time$
end
//---------
func hitKey()
setFunctionKey(0,localizedString("ここを押してください","Hit This Button"),'!')
displayFunctionKey(YES,0,0)
while inkey()=0
endwhile
cls()
displayFunctionKey(NO,0,0)
endfunc
//---------
func str localizedString(js;str,es;str)
if isLocalizeJapan() then return(js)
return (es)
endfunc
//---------
Zipファイル :XBetc.zip
0 件のコメント:
コメントを投稿