Find largest left truncatable prime in a given base: Difference between revisions

m
(→‎{{header|Fortran}}: Multi-digit arithmetic...)
Line 413:
</lang>
 
As checked via earlier tests, using a fixed value for BIGLIMIT that is "surely big enough" enables faster execution thatthan variable sizes. Now, BIGBASE is a variable, with a view to <code>DO BIGBASE = 3,17</code> and almost everything else remains the same, though with BIGBASE being a rather small number, there is no need to employ 64-bit variables via INTEGER*8 at certain places. The use of BIGORDER is disrupted and routines employing it should be avoided or adjusted, thus in BIGTASTE, adding <codelang Fortran> IF (MOD(BIGBASE,10).NE.0) STOP "BIGTASTE expects powers of 10" !Alas. Otherwise the "E" formalism fails.</codelang> for example. The changes produce <lang Fortran> SUBROUTINE BIGWRITE(F,B) !Show B.
INTEGER F !I/O unit number.
TYPE(BIGNUM) B !The number.
Line 442:
END FUNCTION BIGISPRIME !Can't be bothered with ISPRIME from PRIMEBAG.
</lang>
Which is to say that BIGWRITE will show the digits of a number as decimal numbers separated by periods rather than involving letters as additional digit symbols, while BIGTEN will prepare a text version in base ten, whatever BIGBASE is. Finally, BIGMRPRIME quitsused to quit if BIGBASE iswere less than four, because it wants to test numbers not exceeding four by only inspecting a single digit of the big number, so that it can for larger numbers perform a direct test for divisibility by two and three without rejecting those numbers as primes just in case it is invoked for them. So ... <lang Fortran>Catch some annoying cases, to protect the direct tests for divisibility by two and three...
IF (N.LAST.LE.2) THEN !A smallish number? I want to compare to four, but BIGBASE might be two.
NR = BIGVALUE(N) !Surely so.
Line 547:
</lang>
 
And the results, slightly edited to remove a few columns of spaces...
<pre>
Working in bases 3 to 17 there are 7 single-digit primes: 2, 3, 5, 7, 11, 13, 17
 
Base Digits Count Maximum Value = (in base)
3 3 1 23 = 2.1.2
4 6 3 4091 = 3.3.3.3.2.3
5 6 1 7817 = 2.2.2.2.3.2
6 17 1 4836525320399 = 1.4.1.4.1.5.1.1.4.1.4.4.5.1.4.3.5
7 7 1 817337 = 6.6.4.2.6.2.3
8 15 1 14005650767869 = 3.1.3.6.3.6.1.6.5.5.3.7.7.7.5
9 10 3 1676456897 = 4.2.8.4.4.8.4.4.6.5
10 24 1 357686312646216567629137 = 3.5.7.6.8.6.3.1.2.6.4.6.2.1.6.5.6.7.6.2.9.1.3.7
11 9 1 2276005673 = 10.6.8.8.2.2.8.2.7
12 32 1 13092430647736190817303130065827539 = 4.7.1.10.3.4.10.1.6.4.2.5.9.11.10.1.6.11.3.2.4.10.11.8.10.3.2.11.7.8.1.7
13 8 4 812751503 = 12.12.4.12.8.12.6.5
14 26 2 615419590422100474355767356763 = 13.9.6.7.12.12.13.6.3.3.8.8.5.2.2.6.1.9.8.8.3.10.7.13.2.3
15 22 1 34068645705927662447286191 = 6.12.6.12.2.12.14.2.12.14.14.14.10.4.8.2.6.14.6.4.2.11
16 25 1 1088303707153521644968345559987 = 13.11.12.7.15.11.10.2.4.15.14.6.10.14.12.4.6.2.10.11.15.6.3.11.3
17 11 1 13563641583101 = 6.12.6.6.12.12.4.12.12.8.3
 
The MR prime test makes a series of trials, stopping early
1,220

edits