Jump to content

Primes: n*2^m+1: Difference between revisions

→‎{{header|ALGOL 68}}: Tweaks and do thew stretch goals
(Added Java)
(→‎{{header|ALGOL 68}}: Tweaks and do thew stretch goals)
Line 19:
{{works with|ALGOL 68G|Any - Tested with release 3.0.3 under Windows}}
{{libheader|ALGOL 68-primes}}
Doesn't attemptHandles the stretchier stretch goal, butthough doesyou showwill the primes uphave to 400wait witha up to 2000 digits and m at most 600 which turns out to be all of them except for 383while...<br/>
The valuesMost of the primes are interesting - most will fit in 64 bits (those up to 45 will fit in 16 bits) but there are a small number that have hundreds or thousands of digits. <br>
<b>NB</b> the primes.incl.a68 source is available on a page in Rosetta Code - see the <b>library</b> above.
<syntaxhighlight lang="algol68">
Line 26:
# such that 1+n*2^m is prime #
PR read "primes.incl.a68" PR # include peime utilities #
PR precision 20008000 PR # set the precision of LONG LONG INT #
INT max m := 6008000; # maximum m we will consider #
FOR n TO 400 DO
INT m := 0;
LONG LONG INT twonx2 to m := 1n;
LONG LONG INT p := 0;
BOOL not found := TRUEFALSE;
WHILE notNOT found AND m <= max m DO
IF notNOT ( found := NOT is probably prime( p := ( LENG LENG n * twonx2 to m ) + 1 ) ) THEN
twonx2 to m *:= 2;
m +:= 1
FI
OD;
IF notNOT found THEN
print( ( whole( n, -3 ), " not found", newline ) )
ELSE
Line 431:
381 3: 3049
382 0: 383
383 6393: 11693945185971565896920916176753769281418376445302724140914106576604960252116205468905429628661873192664799900323401294531072465400997845029722990758855393414014415817179228695517839305455702961095094596926622802342799137107509767542153683280899327558274011281588755909890607960835140712630830933978801393590855371457894042968287926562847826310125559303901351824980311279986492793008248059208985097459095049075732193161126922389950080848742183055141518931962329796357335158955758486061360294773463111842316561192036096585088267052290025273980611139612478214293303564141730470933187279751846912161098280963960686648202780382930927114525552446602357404550468641236474238897222372272898562140228039886991631673186995098587756569010989657598363351856992206826342175536967926902668804937341514786382018872919876784539436965319822540039220122728568129762675989071883516915894567537630751801497223803135172643203770169327233350522822938630733126833423559124391441973547309619943019237705312515304113424366223388373606440335025932390399945086075175009569272136997988977568262327875607690344516747889133920438003737328060362069562108376086129279385800262195985974144460914705464874882401864174074796383557151951711000378565395148939760434428093058777242253682181813425273399277638142811972296863003382484684788329148214958434057306251885787781329925372401240556666727438408378656900945061970219566055969587385482421092779185798692904507774583223151161566406541599486350580593707153172641891804260963429951215526999443852964537303345106153870841180251403751871193132336680841124129779119999935597712685839886558769823834654994044516702436738265181698869580022472787153167463772595005393815295009535991557511340157179280662197799109181549751673455040271529561595718940092424231253150263268513067972937042222806102175350331146290864120703025608712817763221723427454002746818270565050919821097445991953785331131470462682015972815241620750337
383 not found
384 1: 769
385 8: 98561
3,038

edits

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