用Mathematica编写以下两题

来源:百度知道 编辑:UC知道 时间:2024/06/01 08:43:18
一,编写程序求1-100内的素数并输出这些素数
二,编写一个排序函数,输入A=[a1,a2.....an]全自动把A中元素排序并输出排序结果

Pascal语言描述,偏离题意要求 Mathematica 。

一、
看我的筛选法求素数(1500000的数据量一秒之内运算完成):
var
a,b,tt:integer;
f:array[1..100]of integer;
procedure find(l,r:integer);
var
i,j:integer;
begin
for i:=2 to round(sqrt(r)) do
if not f[i] then
for j:=2 to r div i do
f[i*j]:=true;
f[1]:=true;
for i:=l to r do
if not f[i] then write(i,' ');
writeln;
end;
begin
readln(a,b);
fillchar(f,sizeof(f),false);
find(a,b);
end.
输入“1 100”就可以了,这是我直接打的,没有调试、编译,楼主自己参考吧。

二、
简单的字符串的处理,不要让我在这里废话了。