41 lines
1.1 KiB
Text
41 lines
1.1 KiB
Text
func IsPrime(N); \Return 'true' if N >= 3 is prime
|
|
int N, D;
|
|
[if rem(N/3) = 0 then return N = 3;
|
|
D:= 5;
|
|
while D*D <= N do
|
|
[if rem(N/D) = 0 then return false;
|
|
D:= D+2;
|
|
if rem(N/D) = 0 then return false;
|
|
D:= D+4;
|
|
];
|
|
return true;
|
|
];
|
|
|
|
int Prod, Num, Count, Limit;
|
|
real Sum;
|
|
[IntOut(0, 1); ChOut(0, ^ );
|
|
IntOut(0, 2); ChOut(0, ^ );
|
|
Prod:= 2; Num:= 3; Count:= 1;
|
|
loop [if IsPrime(Num) then
|
|
[Prod:= Prod*Num;
|
|
IntOut(0, Prod); ChOut(0, ^ );
|
|
Count:= Count+1;
|
|
if Count >= 9 then quit;
|
|
];
|
|
Num:= Num+2;
|
|
];
|
|
CrLf(0);
|
|
Num:= 3; Count:= 1; Sum:= Log(2.); Limit:= 10;
|
|
loop [if IsPrime(Num) then
|
|
[Sum:= Sum + Log(float(Num));
|
|
Count:= Count+1;
|
|
if Count = Limit then
|
|
[IntOut(0, fix(Sum-0.5)+1); ChOut(0, ^ );
|
|
if Limit >= 1_000_000 then quit;
|
|
Limit:= Limit*10;
|
|
];
|
|
];
|
|
Num:= Num+2;
|
|
];
|
|
CrLf(0);
|
|
]
|