GMP Native Interface for .NET
gmp_libmpz_probab_prime_p Method |
Determine whether n is prime.
Namespace: Math.Gmp.Native
Assembly: Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)

public static int mpz_probab_prime_p( mpz_t n, int reps )
Public Shared Function mpz_probab_prime_p ( n As mpz_t, reps As Integer ) As Integer
public: static int mpz_probab_prime_p( mpz_t^ n, int reps )
static member mpz_probab_prime_p : n : mpz_t * reps : int -> int
Parameters
- n
- Type: Math.Gmp.Nativempz_t
The operand integer. - reps
- Type: SystemInt32
The number of Miller-Rabin probabilistic primality tests to perform.
Return Value
Type: Int32Return 2 if n is definitely prime, return 1 if n is probably prime (without being certain), or return 0 if n is definitely non-prime.

This function performs some trial divisions, then reps Miller-Rabin probabilistic primality tests. A higher reps value will reduce the chances of a non-prime being identified as “probably prime”. A composite number will be identified as a prime with a probability of less than 4^(-reps). Reasonable values of reps are between 15 and 50.

// Create, initialize, and set the value of n to 12. mpz_t n = new mpz_t(); gmp_lib.mpz_init_set_ui(n, 12U); // Assert that n is a composite number. Assert.IsTrue(gmp_lib.mpz_probab_prime_p(n, 25) == 0); // Release unmanaged memory allocated for n. gmp_lib.mpz_clear(n);
' Create, initialize, and set the value of n to 12. Dim n As New mpz_t() gmp_lib.mpz_init_set_ui(n, 12UI) ' Assert that n is a composite number. Assert.IsTrue(gmp_lib.mpz_probab_prime_p(n, 25) = 0) ' Release unmanaged memory allocated for n. gmp_lib.mpz_clear(n)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
