public static bool Test(ulong exponent, ref ulong startI, ref mpz_t startS) { if (!Collection.Primes.IsPrime((int)exponent) || ((exponent & 3) == 3 && Collection.Primes.IsPrime(((int)exponent << 1) + 1))) { return(false); } mpz_t mersenneNumber = mpz_t.One.ShiftLeft((int)exponent) - 1; return(TrialDivision(exponent, mersenneNumber) && LucasLehmerTest.Fastest(exponent, mersenneNumber, ref startI, ref startS)); }
private async Task Computations() { Busy.Visibility = Visibility.Visible; PrimeNumberState result; var token = _token.Token; switch (_options.Type) { case PrimalityTestType.Aks: result = await Task.Run(() => AksTest.IsPrime(_number, token), token); break; case PrimalityTestType.Fermat: { var k = GetNumberOfIterations(); if (k == -1) { Busy.Visibility = Visibility.Hidden; return; } result = await FermatTest.IsPrime(_number, k, token); } break; case PrimalityTestType.LucasLehmer: result = await LucasLehmerTest.IsPrime(_number, token); break; case PrimalityTestType.Pepin: result = await Task.Run(() => PepinTest.IsPrime(_number), token); break; case PrimalityTestType.RabinMiller: { var k = GetNumberOfIterations(); if (k == -1) { Busy.Visibility = Visibility.Hidden; return; } result = await RabinMiller.IsPrime(_number, k, token); } break; case PrimalityTestType.SolovayStrassen: { if (!long.TryParse(_number.ToString(), out var num)) { MessageBox.Show("This number too big to use this method.\nPlease select another primality test.", "Result", MessageBoxButton.OK); Busy.Visibility = Visibility.Hidden; return; } var k = GetNumberOfIterations(); if (k == -1) { Busy.Visibility = Visibility.Hidden; return; } result = await SolovayStrassen.IsPrime(num, k, token); break; } default: { Busy.Visibility = Visibility.Hidden; return; } } MessageBox.Show($"Your number is {Enum.GetName(typeof(PrimeNumberState), result)}", "Result"); Busy.Visibility = Visibility.Hidden; }