public void Test8() { PrimeNumbers PrimNum = new PrimeNumbers(); bool output = PrimNum.IsAPrime(64); Assert.Equal(output.ToString(), IsPrime.False.ToString()); }
//Prime Numbers private void Button_Click_3(object sender, RoutedEventArgs e) { ITrack track = new PrimeNumbers(); race.track = track; this.Frame.Navigate(typeof(MainPage), race); }
private static List <int> GetPrimeFactors(int num, int limit) { var res = new List <int>(); foreach (var prime in PrimeNumbers.GetAllPrimes()) { if (prime > num / 2) { break; } var pow = 0; var temp = num; while (temp % prime == 0) { temp /= prime; pow++; } if (pow > 0) { res.Add((int)(Math.Pow(prime, pow))); if (res.Count >= limit) { break; } } } return(res); }
public void ShouldReturnPrimesUnder30() { // Arrange var primeNumbers = new PrimeNumbers(); var primesReturned = false; var primesGenerated = new List <int>(); // Primes taken from https://oeis.org/A000040 var primesUnder30 = new List <int> { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; // Act foreach (var prime in primeNumbers.Generate(30)) { Assert.IsTrue(primesUnder30.Contains(prime), $"Unexpected prime: {prime}"); primesGenerated.Add(prime); primesReturned = true; } // Assert Assert.IsTrue(primesReturned, "Expected the on prime action to be called."); Assert.IsFalse(primesUnder30.Except(primesGenerated).Any(), "Expected all primes under 30 to be generated."); }
public void Start() { var primes = PrimeNumbers.GetPrimeSet(10000); int maxN = -1; int bMax = -99999; int aMax = -99999; for (int a = -999; a < 1000; a++) { for (int b = -1000; b <= 1000; b++) { int n = 0; var estimatedPrime = n * n + a * n + b; while (primes.Contains(estimatedPrime)) { n++; estimatedPrime = n * n + a * n + b; } if (n > maxN) { maxN = n; aMax = a; bMax = b; } } } Trace.WriteLine($"Max n = {maxN}, a = {aMax}, b = {bMax}"); }
public string PutById(int id) { List <Prime> primes = PrimeNumbers.GetPrimes(id); _service.Save(primes); return("Ok"); }
public void PrimeFindIndexOfElementFails() { PrimeNumbers prime = new PrimeNumbers(); int input = 103; prime.FindIndex(input); }
private void primeNumber_Click(object sender, RoutedEventArgs e) { int n = Int32.Parse(inputTextBox.Text); resultLabel.Text = PrimeNumbers.FindPrimeNumbersSync(n).ToString();; }
public void PrimeGetNextNonPrime() { PrimeNumbers prime = new PrimeNumbers(); int input = 105; prime.GetNext(input); }
public void Test1(int userInput, int expected) { PrimeNumbers pnum = new PrimeNumbers(); int res = PrimeNumbers.GetPrime(userInput); Assert.Equal(expected, res); }
public void GetListofPrimeNumbers_first_prime_number_is_2() { PrimeNumbers primeNumbers = new PrimeNumbers(); var primeNumbersList = primeNumbers.GetListofPrimeNumbers(100); Assert.AreEqual(primeNumbersList.ToList()[0], 2); }
public void Nine() { int a = 9; bool result = PrimeNumbers.CheckPrime(a); Assert.False(result); }
public void GetListofPrimeNumbers_Should_return_not_null() { PrimeNumbers primeNumbers = new PrimeNumbers(); var primeNumbersList = primeNumbers.GetListofPrimeNumbers(100); Assert.IsNotNull(primeNumbersList); }
public void PrimeTest1(int first, int expected) { PrimeNumbers num = new PrimeNumbers(); int result = num.GetPrime(first); Assert.Equal(expected, result); }
public void PrimeShouldPrintFirstNumber() { PrimeNumbers prime = new PrimeNumbers(); int expected = 1; int actual = prime.GetFirst(); Assert.AreEqual(expected, actual); }
public void Test7() { PrimeNumbers PrimNum = new PrimeNumbers(); bool output = PrimNum.IsAPrime(89); Assert.Equal(output.ToString(), IsPrime.True.ToString()); }
public void Start() { var primes = PrimeNumbers.GetPrimeSet(10000000); foreach (var prime in primes.OrderByDescending(z => z)) { var digits = Numbers.ToDigits(prime); Array.Sort(digits); bool isPandigital = true; for (int i = 0; i < digits.Length; i++) { if (i + 1 != digits[i]) { isPandigital = false; break; } } if (isPandigital) { Console.WriteLine($"Highest pandigital prime is {prime}"); break; } } }
public void Three() { int a = 3; bool result = PrimeNumbers.CheckPrime(a); Assert.True(result); }
public void Test1(int userInput, int expected) { PrimeNumbers PNums = new PrimeNumbers(); int result = PNums.GetPrime(userInput); Assert.Equal(expected, result); }
public static long Solve() { //long answer = 2L * 5L * 3L * 7L * 11L * 13L * 17L * 19L * 23L * 2L * 2L; double ratio = 15499.0 / 94744.0; //0.1635881955585578 var primes = new PrimeNumbers(); long denominator = 1L; double r = 1; foreach (var prime in primes) { // 2L * 5L * 3L * 7L * 11L * 13L * 17L * 19L * 23L r = (denominator * prime).phi() / ((denominator * prime) - 1.0); if (r > ratio) denominator *= prime; else { r = denominator.phi() / (denominator - 1.0); break; } } while (r > ratio) { denominator *= primes.First(); r = denominator.phi() / (denominator - 1.0); if (r < ratio) break; } return denominator; }
public void TestPrimes(int n, int expected) { PrimeNumbers numbers = new PrimeNumbers(); int result = numbers.GetPrime(n); Assert.Equal(expected, result); }
public void NintySeven() { int a = 97; bool result = PrimeNumbers.CheckPrime(a); Assert.True(result); }
/// <summary> /// Performs prime number search /// </summary> private async void Start() { using (StartCommand.RunWithDisabled()) using (_cancellationTokenSource = new CancellationTokenSource()) { var progress = new ProgressFilterProxy(new Progress <double>(d => Progress = (int)(d * 100))); try { var primes = await _sieveOfEratosthenesCalculator.MakeSieveAsync((int)NumberRange, progress, _cancellationTokenSource.Token); Progress = 100; ResultText = $"Znaleziono {primes.Count} liczb pierwszych"; PrimeNumbers.Clear(); PrimeNumbers.AddRange(primes, ObservableCollectionEx <int> .ECollectionChangeNotificationMode.Reset); } catch (OperationCanceledException ex) when(ex.CancellationToken == _cancellationTokenSource.Token) { ResultText = "Operacja zatrzymana"; PrimeNumbers.Clear(); } finally { _cancellationTokenSource = null; } } }
public void TestAll(int userNum, int expected) { PrimeNumbers primeNum = new PrimeNumbers(); int final = primeNum.GetPrime(userNum); Assert.Equal(expected, final); }
public static void Start() { var circularPrimes = new List <int>(); var primes = PrimeNumbers.GetPrimeSet(1000000); foreach (var prime in primes) { var digits = Numbers.ToDigits(prime); bool isCircular = true; for (int i = 1; i < digits.Length; i++) { if (!primes.Contains(Rotate(digits))) { isCircular = false; } } if (isCircular) { circularPrimes.Add(prime); } } Console.WriteLine($"Number of circular primes below one million: {circularPrimes.Count}"); }
public void PrimeShouldPrintNextNumber() { PrimeNumbers prime = new PrimeNumbers(); int input = 2; int expected = 3; int actual = prime.GetNext(input); Assert.AreEqual(expected, actual); }
public void Test5() { int choice = 5; ArrayList myList = new ArrayList(); PrimeNumbers.CreatePrimeList(myList); Assert.Equal(11, PrimeNumbers.GetPrime(myList, choice)); }
public void PrimeShouldPrintVariableSequenceOfNumbers() { PrimeNumbers prime = new PrimeNumbers(); int input = 8; int[] expected = new int[] { 1, 2, 3, 5, 7, 11, 13, 17 }; int[] actual = prime.GetSequence(input); CollectionAssert.AreEqual(expected, actual); }
public void PrimeShouldPrintFirstNumber() { PrimeNumbers prime = new PrimeNumbers(); int expected = 2; int actual = prime.GetFirst(); Assert.AreEqual(expected, actual); }
public ulong Run(ulong targetNumber) { var primes = new PrimeNumbers(); var primeFactors = primes.GetPrimeFactors(targetNumber); return(primeFactors.Max()); }
public void Execute() { var primeNumber = new PrimeNumbers(); var number = primeNumber.RandomNumber(0, 5000); primeNumber.PrimeNumberString(number); }
public void PrimePrintSequenceOfNumbers() { PrimeNumbers prime = new PrimeNumbers(); int length = 7; string expected = "1 2 3 5 7 11 13"; string actual = prime.ToString(prime.GetSequence(length)); Assert.AreEqual(expected, actual); }
public Rsa(Int64 firstPrime, Int64 secondPrime) { if (PrimeNumbers == null || !PrimeNumbers.Any()) { GeneratorPrimeNumbers(MinValue, MaxValue); } GeneralKeys(firstPrime, secondPrime); }
public void GetListofPrimeNumbers_one_element_basic_test() { PrimeNumbers primeNumbers = new PrimeNumbers(); var primeNumbersList = primeNumbers.GetListofPrimeNumbers(1); Assert.IsNotNull(primeNumbersList); Assert.AreEqual(primeNumbersList.ToList()[0], 2); }
public void GetListofPrimeNumbers_list_count_same_as_input_number() { PrimeNumbers primeNumbers = new PrimeNumbers(); int count = 100; var primeNumbersList = primeNumbers.GetListofPrimeNumbers(count); Assert.AreEqual(primeNumbersList.Count(), count); }
public int Execute(int numberToFactor1, int numberToFactor2) { var primeNumbers = new PrimeNumbers().Execute(Min(numberToFactor1, numberToFactor2)).ToArray(); var factors1 = GetFactors(InitFactorsList(), numberToFactor1, FilterPrimeNumbers(numberToFactor1, primeNumbers).ToArray()); var factors2 = GetFactors(InitFactorsList(), numberToFactor2, FilterPrimeNumbers(numberToFactor2, primeNumbers).ToArray()); var factorGroups1 = factors1.GroupBy(o => o).Select(g => new FactorGroup(g.Key, g.Count())); var factorGroups2 = factors2.GroupBy(o => o).Select(g => new FactorGroup(g.Key, g.Count())); var minFactorGroups = from g1 in factorGroups1 join g2 in factorGroups2 on g1.Factor equals g2.Factor select new FactorGroup(g2.Factor, Min(g1.Count, g2.Count)); return minFactorGroups.Select(Power).Multiply(); }
public static long Solve() { var longest = 0; var count = 0; var limit = 1000000; var primes = new PrimeNumbers(limit); var test = 0; var queue = new Queue<int>(); foreach (var prime in primes) { test += prime; if (test >= limit) break; queue.Enqueue(prime); if (primes.IsPrime(test) && queue.Count > count) { longest = test; count = queue.Count; } } while (!primes.IsPrime(test)) { queue.Dequeue(); test = queue.Sum(); if (primes.IsPrime(test) && queue.Count > count) { longest = test; count = queue.Count; } } return longest; }
static void Main() { int n = Int32.Parse(Console.ReadLine()); bool[] primes = new bool[n+1]; for (int i = 2; i <= n; i++) { primes[i] = true; } PrimeNumbers prime = new PrimeNumbers(); prime.SieveOfEratosthenes(primes); for (int i = 2; i <= n; i++) { if (primes[i] == true) { Console.Write(i + " "); } } Console.WriteLine(); }
public void Teardown() { _instance = null; }
public void Setup() { _instance = new PrimeNumbers(); }
public void PrimeEnsureICanCreateClassInstance() { PrimeNumbers prime = new PrimeNumbers(); Assert.IsNotNull(prime); }
public int Execute(int nthPrimeNumber) { var primeNumbers = new PrimeNumbers().Execute(10000).ToArray(); return primeNumbers[nthPrimeNumber - 1]; }
public void TestCleanup() { primeNumbers = null; }
public void TestInitialize() { primeNumbers = new PrimeNumbers(); }