![]() |
|
|
#155 |
|
Aug 2006
3·1,993 Posts |
What is this supposed to return?
|
|
|
|
|
|
#156 | |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Quote:
|
|
|
|
|
|
|
#157 |
|
Aug 2006
3·1,993 Posts |
|
|
|
|
|
|
#158 | |
|
May 2010
Prime hunting commission.
168010 Posts |
Quote:
Testing for c100: 317305983867984894552374513880330942325323897104138220309522782479794265138440652957829496038865542387 Result = 31 ms. c200: 47 ms. c400: 78 ms. c800: 218 ms. c1600: 702 ms. p200: 47 ms. p400: 94 ms. p800: 219 ms. Last fiddled with by 3.14159 on 2010-07-22 at 04:24 |
|
|
|
|
|
|
#159 | |
|
Aug 2006
597910 Posts |
Quote:
But for 101 it returns 1, not 101. |
|
|
|
|
|
|
#160 | |
|
May 2010
Prime hunting commission.
24·3·5·7 Posts |
Quote:
≈ 2000 digits: Approximately 1 second. ≈ 1000 digits: About 0.28 seconds. ≈ 3000 digits: About 2.65 seconds. Testing the second largest prime I have ever found: 94.25 seconds. Great. It's suitable for small primes and mid-sized primes. Also: It may return either: Mod(1, n), or Mod(n-1, n) for primes. Params set: SPRP = Trial division + Miller-Rabin test (Primality confirmation: Perform here. Be warned: 900+ digits, it uses Miller-Rabin as a test, use this only for small integers. For larger cases, use PARI's isprime(n) function.) WPRP = Fermat's primality test" Hey: I thought of something: I'm going to code the original 7-step test, and see by how much it is slower, in the long run. Tips? Here's my long-winded guess: Code:
primetest(n) = {
if(ispower(n) == 1,print(1));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,print(n));
my(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
};
Last fiddled with by 3.14159 on 2010-07-22 at 04:59 |
|
|
|
|
|
|
#161 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Last fiddled with by science_man_88 on 2010-07-22 at 10:04 |
|
|
|
|
|
|
#162 |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Testing.. Dammit. I have a syntax error. The error reads:
Code:
*** Mod: incorrect type in Rg_to_Fl. Last fiddled with by 3.14159 on 2010-07-22 at 12:19 |
|
|
|
|
|
#163 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
|
|
|
|
|
|
#164 | |
|
Aug 2006
3·1,993 Posts |
Quote:
2. You can't raise b to a power mod n unless you know what b is. (I suggest adding an optional argument for b.) 3. Don't print n when Mod(b, n)^(n-1) == 1, instead return n. 4. Change the line n == -1 to an if statement returning either 0 or n. I see four steps, not seven (power, trial division, Fermat test, M-R test). Also I suggest adding an addhelp explaining how the function works: you wouldn't want someone doing Code:
if(primetest(n), print(n" is prime")) Last fiddled with by CRGreathouse on 2010-07-22 at 13:05 |
|
|
|
|
|
|
#165 |
|
May 2010
Prime hunting commission.
32208 Posts |
.. I can't code it altogether. It has to be done in separate tests for the original.
Last fiddled with by 3.14159 on 2010-07-22 at 13:13 |
|
|
|
![]() |
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 |