Jump to content

Greatest prime dividing the n-th cubefree number: Difference between revisions

Added XPL0 example.
m (Promoted to ‘full’ task.)
(Added XPL0 example.)
 
Line 1,424:
 
Took 36.458647 seconds.
</pre>
 
=={{header|XPL0}}==
Simple brute force takes 43 seconds on Raspberry Pi 4.
<syntaxhighlight lang "XPL0">func MaxFactor(N); \Return maximum factor of N that's cube-free
int N, Div, Count, Max;
[Max:= N; Div:= 2;
while N >= Div*Div do
[Count:= 0;
while rem(N/Div) = 0 do
[Count:= Count+1;
if Count = 3 then return 0;
Max:= Div;
N:= N/Div;
];
Div:= Div+1;
];
if N > 1 then Max:= N; \prime
return Max;
];
 
int I, N, Pow10, Fac;
[Format(4, 0);
I:= 1; N:= 0; Pow10:= 1000;
loop [Fac:= MaxFactor(I);
if Fac # 0 then
[N:= N+1;
if N <= 100 then
[RlOut(0, float(Fac));
if rem(N/10) = 0 then CrLf(0);
]
else if N = Pow10 then
[IntOut(0, Pow10); Text(0, "th term of a[n] is ");
IntOut(0, Fac); CrLf(0);
if Pow10 = 10_000_000 then quit;
Pow10:= Pow10*10;
];
];
I:= I+1;
];
]</syntaxhighlight>
{{out}}
<pre>
1 2 3 2 5 3 7 3 5 11
3 13 7 5 17 3 19 5 7 11
23 5 13 7 29 5 31 11 17 7
3 37 19 13 41 7 43 11 5 23
47 7 5 17 13 53 11 19 29 59
5 61 31 7 13 11 67 17 23 7
71 73 37 5 19 11 13 79 41 83
7 17 43 29 89 5 13 23 31 47
19 97 7 11 5 101 17 103 7 53
107 109 11 37 113 19 23 29 13 59
1000th term of a[n] is 109
10000th term of a[n] is 101
100000th term of a[n] is 1693
1000000th term of a[n] is 1202057
10000000th term of a[n] is 1202057
</pre>
295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.