![]() |
[QUOTE=CRGreathouse;228940]Depends on what size primes you store and how you store them, naturally.[/QUOTE]
well if we encode it as characters for each digit it gets inefficient real quick (almost like BCD in ASM I think), I don't know the best way to encode them efficiently unless maybe we convert them to hex to take less room than the decimal and hex or another power of 2 base is easier for me to convert to binary(yes I've learned that part lol). |
[QUOTE=science_man_88;228942]well if we encode it as characters for each digit it gets inefficient real quick (almost like BCD in ASM I think), I don't know the best way to encode them efficiently unless maybe we convert them to hex to take less room than the decimal and hex or another power of 2 base is easier for me to convert to binary(yes I've learned that part lol).[/QUOTE]
So store them natively in binary, taking k bits to store (naturally!) a k-bit prime. You can even do better: store all but the last bit, unless the prime is 2, in which case store it as 0. You'll need some way to delimit the primes, though. |
[QUOTE=CRGreathouse;228946]So store them natively in binary, taking k bits to store (naturally!) a k-bit prime. You can even do better: store all but the last bit, unless the prime is 2, in which case store it as 0.
You'll need some way to delimit the primes, though.[/QUOTE] let me guess the last bit won't matter as it will always be one except when the decimal representation of the prime is 2. yeah what to separate them in storage with. |
[QUOTE=science_man_88;228948]let me guess the last bit won't matter as it will always be one except when the decimal representation of the prime is 2. yeah what to separate them in storage with.[/QUOTE]
One way would be to used fixed width. Store only 65-bit primes, so every 64 bits is a new prime. There are 412246861431389469 65-bit primes, so you shouldn't run out... unless you have more than 206123 TB. You could even left-pad with 0s and include primes of up to 65 bits. This gives you 837903145466607212 to work with (and moves the storage for all of them to 418951 TB). |
[CODE]a=0;forallprime(1,2^100,p->a=a+1;if(ispower(p+1),print(ispower(p+1)","p","a)))[/CODE]
this can't be efficient |
There are many more primes than (proper) powers, and as it happens ispower is a lot slower than isprime. So if you're able, set up the loop the other way: loop over powers and check the the primality of n-1.
This way you're checking something like 1.126 * 10[SUP]15[/SUP] numbers instead of 1.267 * 10[SUP]30[/SUP]. Edit: 1125910730446094 instead of 1.856(1) * 10[SUP]28[/SUP], assuming (wrongly) that you've precalculated primes up to 2[SUP]100[/SUP]. |
[QUOTE=CRGreathouse;228962]There are many more primes than (proper) powers, and as it happens ispower is a lot slower than isprime. So if you're able, set up the loop the other way: loop over powers and check the the primality of n-1.[/QUOTE]
Two words. Algebraic factors. Zero clock cycles. |
[QUOTE=axn;228965]Two words. Algebraic factors. Zero clock cycles.[/QUOTE]
I was actually more interested in the general issue of looping over primes and powers than the specific one of finding primes one less than a power. |
[QUOTE=axn;228965]Two words. Algebraic factors. Zero clock cycles.[/QUOTE]
I can't even remember the think other than 2kp+1 that anyone told me lol. |
The suggestion was that b - 1 is a factor of b^k - 1, so unless b = 2 this cannot be a prime. If b = 2 then you're just looking for Mersenne primes.
|
best I can do of summing up the LL test is:
s=2*y*(2*k*p+1) s=4*y*k*p+(2*y) but this is useless obviously |
| All times are UTC. The time now is 23:15. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.