SAS中文论坛
标题:
找质数(素数)
[打印本页]
作者:
shiyiming
时间:
2010-1-12 09:59
标题:
找质数(素数)
最近天气比较冷,人气也不旺,现在弄个小题目热热身:
寻找质数(素数)集合,一直到最小的两质数之差为62.
作者:
shiyiming
时间:
2010-1-13 05:19
标题:
Re: 找质数(素数)
用C,Matlab等都很好编,用SAS不会,现在只会用SAS读读数据整理整理再means,glm这种分析一下。。。期待高手解答~~
作者:
Qiong
时间:
2010-1-13 09:16
标题:
Re: 找质数(素数)
不明白呀,跟集合有什么关系?
是由小到大的找质数,找到间隔大于等于62?
作者:
shiyiming
时间:
2010-1-13 11:55
标题:
Re: 找质数(素数)
Does this work? <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
[code:2eemt1d1]data primes(keep = prime);
retain difference testOn previousPrime;
prime = 2;
output;
difference = 0;
testOn = 3;
do while (difference <= 62);
isPrime = 1;
do divisor = 3 to int(sqrt(testOn)) by 2;
if mod(testOn, divisor) = 0 then do;
isPrime = 0;
leave;
end;
end;
if isPrime = 1 then do;
prime = testOn;
difference = prime - previousPrime;
previousPrime = Prime;
output;
end;
testOn = testOn + 2;
end;
run;[/code:2eemt1d1]
欢迎光临 SAS中文论坛 (https://mysas.net/forum/)
Powered by Discuz! X3.2