对了,谁提供一个5位数的加强程序就给200分,呵呵作者: yangff 时间: 2008-7-2 18:48
a=[]
a[0] = 0
a[1] = 0
for i in 2..99999
a = 0
end
for i in 2..99999
a = 1
b = i*2
while b <=99999
a = 0
b += i
end
end
for i in 2..99999
print i.to_s + "是质数" if a == 1
end [LINE]1,#dddddd[/LINE]系统信息:本贴获得楼主认可,66RPG感谢您的热情解答~作者: lxczzzcxl 时间: 2008-7-2 19:24
LS咋没显示合数的捏?
给60吧 [LINE]1,#dddddd[/LINE]版主对此帖的认可:『感谢共享』,积分『+50』。作者: yangff 时间: 2008-7-2 21:14
for i in 2..99999
print i.to_s + "是质数" if a == 1
end
=》
for i in 2..99999
print i.to_s + "是质数" if a == 1
print i.to_s + "是合数" if a == 0
end
有什么囧的,美国的那个素数检验计算机就是这样做的.让一个未知的数去除数据库里已知的素数,不被整除则为素数.!如此循环往下.作者: orochi2k 时间: 2009-7-27 15:53
其实RUBY根本不适合干这事,还是用汇编吧 囧
理由:
1,程序不长
2,开发效率没要求
3,执行效率要求很高作者: 一路一风尘 时间: 2009-7-27 19:06
提示: 作者被禁止或删除 内容自动屏蔽作者: DeathKing 时间: 2009-7-27 19:12
说…………RGSS算质数不如VB或VC吧?作者: mafiaboy 时间: 2009-7-31 15:27
PY版的(跟ruby好像)
h = 0
leap = 1
from math import sqrt
from sys import stdout
for m in range(1,20000):
k = int(sqrt(m + 1))
for i in range(2,k + 1):
if m % i == 0:
leap = 0
break
if leap == 1:
print '%-4d' % m
h += 1
if h % 10 == 0:
print ''
leap = 1
print 'The total is %d' % h作者: mafiaboy 时间: 2009-7-31 15:32
恩 这一个是最快的求100以内质数方法(转载)
DSEG SEGMENT
count dw 0;存放素数的个数
sum dw 0;存放素数的和
sushu db 100 dup(?);存放素数
msgsushu db 'all of sushu are:','$';显示素数的提示信息
msgcount db 0dh,0ah,'count of sushu is:',0dh,0ah,'$';显示素数个数的提示信息
msgsum db 0dh,0ah,'sum of sushu is:',0dh,0ah,'$';显示素数和的提示信息
DSEG ENDS
CSEG SEGMENT
assume cs:CSEG, ds:DSEG
MAIN PROC FAR ;主程序入口
call jisuan;将100以内素数的个数存入COUNT单元中,素数的和存入SUM单元中,并将素数存入内存自SUSHU开始的单元中
lea dx,msgsushu;显示素数的提示信息
mov ah,9
int 21h
call dispsushu;显示素数
lea dx,msgcount;显示素数个数的提示信息
mov ah,9
int 21h
call dispcount;显示素数个数
lea dx,msgsum;显示素数和的提示信息
mov ah,9
int 21h
call dispsum;显示素数和
mov ah,1;按任意键退出
int 21h
mov ax, 4c00h ;程序结束,返回到操作系统系统
int 21h
MAIN ENDP