Jump to content

Truncatable primes: Difference between revisions

Added Bracmat example
(Added Bracmat example)
Line 156:
Press Enter
</pre>
 
=={{header|Bracmat}}==
Primality test: In an attempt to compute the result of taking a (not too big, 2^32 or 2^64, depending on word size) number to a fractional power, Bracmat computes the prime factors of the number and checks whether the powers of prime factors make the fractional powers go away. If the number is prime, the output of the computation is the same as the input.
<lang bracmat>( 1000001:?i
& whl
' ( !i+-2:>0:?i
& !i:?L
& whl'(!L^1/2:#?^1/2&@(!L:% ?L))
& !L:~
)
& out$("left:" !i)
& 1000001:?i
& whl
' ( !i+-2:>0:?i
& !i:?R
& whl'(!R^1/2:#?^1/2&@(!R:?R %@))
& !R:~
)
& out$("right:" !i)
)</lang>
Output:
<pre>left: 998443
right: 739399</pre>
 
=={{header|C}}==
483

edits

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