![]() |
|
|
#166 |
|
Aug 2006
3×1,993 Posts |
OK. Can you make the fixes I (and sm88) suggested to your test?
Last fiddled with by CRGreathouse on 2010-07-22 at 13:11 |
|
|
|
|
|
#167 | |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Quote:
Results: It lets all the pseudoprimes in. (Tested the well-known example, 1373653) Last fiddled with by 3.14159 on 2010-07-22 at 13:18 |
|
|
|
|
|
|
#168 |
|
Aug 2006
3·1,993 Posts |
Let's see the code! I'll post my version and we can compare.
|
|
|
|
|
|
#169 |
|
May 2010
Prime hunting commission.
168010 Posts |
Here you go:
Code:
primetest(n, b=2) = {
if(ispower(n) == 1,return(0));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,return(n));
my(s=valuation(n-1,2),d=n>>s);
n = Mod(b, n)^d;
if (n == 1, return(n-1));
while(s--,
if (n == -1, return(n));
n = n^2;
);
n == -1
};
Last fiddled with by 3.14159 on 2010-07-22 at 13:32 |
|
|
|
|
|
#170 |
|
Aug 2006
3·1,993 Posts |
I haven't run yours, but it will fail on any prime larger than nextprime(501), since you haven't defined your base.
I have Code:
primetest(n:int,b:int=2) = {
my(s,d);
if(ispower(n),return(0));
forprime(p=2,500,
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1, return(n));
s=valuation(n-1,2);
d=n>>s;
n = Mod(b, n)^d;
if (n == 1, return(1));
while(s--,
if (n == -1, return(1));
n = n^2;
);
n == -1
};
addhelp(primetest, "primetest(n, {b=2}): Returns the smallest prime factor of n, if one is found. Otherwise, returns 0 if the number is composite and 1 if the number passes all tests (in which case it may be prime or pseudoprime).");
|
|
|
|
|
|
#171 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
|
|
|
|
|
|
|
#172 |
|
May 2010
Prime hunting commission.
110100100002 Posts |
The test keeps in all the damn pseudoprimes
Also: Code fixed, == 1 was removed from nth power check. New code = if(ispower(n), return(0));
Last fiddled with by 3.14159 on 2010-07-22 at 13:35 |
|
|
|
|
|
#173 |
|
Aug 2006
135338 Posts |
Sure. IF you don't want that, you'll need some re-coding. Split isSPRP into its own function, then do
Code:
if(!isSPRP(n), return(0)); if(isprime(n), return(n), return(0)) Also, as you already know but probably don't realize ( ), the last result of the program is simply returned. So my code snippet can be simplified toCode:
if(!isSPRP(n), return(0)); if(isprime(n), n, 0) Code:
if(!isSPRP(n), return(0)); if(isprime(n), n) |
|
|
|
|
|
#174 |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
I'm going to check if the SPRP test I implemented as any pseudoprime numbers:
pseudo(n) =!isprime(n)&isSPRP forstep(n=3,1e8,2,if(pseudo(n),print(n)) It just prints me every odd number. Damned thing never does anything right. Let's try: if(pseudo(n),print(n)) Meh. Manual search. Last fiddled with by 3.14159 on 2010-07-22 at 13:47 |
|
|
|
|
|
#176 | |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Quote:
Pseudoprime number found: 58398839626753 = 5403649 * 10807297. (Base 2 only) Wait.. To weed out pseudoprimes I should change b to (random(n)). Success: Now, random bases are tested. Now, to test the same integer length range I did yesterday, to compare timings: ≈ 1000 digits: 312 ms. ≈ 2000 digits: 1.28 seconds ≈ 3000 digits: 3.41 seconds ≈ 13000 digits (second largest prime I've ever found): 134.97 seconds. Last fiddled with by 3.14159 on 2010-07-22 at 14:19 |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wheel Factorization | a1call | Factoring | 11 | 2017-06-19 14:04 |
| Efficient Test | paulunderwood | Computer Science & Computational Number Theory | 5 | 2017-06-09 14:02 |
| LL tests more credit-efficient than P-1? | ixfd64 | Software | 3 | 2011-02-20 16:24 |
| A Wheel | storm5510 | Puzzles | 7 | 2010-06-25 10:29 |
| Most efficient way to LL | hj47 | Software | 11 | 2009-01-29 00:45 |