public static int SpiralPrimes() { float rate = 100; int spiralLength = 1; int primeCount = 0; int lastCorner = 1; int loopCount = 0; while (rate > 0.1) { loopCount++; spiralLength += 2; for (var i = 0; i < 4; i++) { lastCorner += (spiralLength - 1); if (PrimeHelpers.IsPrimeNumber(lastCorner)) { primeCount++; } } rate = (float)primeCount / (float)((loopCount * 4) + 1); } return(spiralLength); }
public static decimal PrimePermutations() { decimal result = 0; int number = 1489; int increasingNumber = 3330; while (number <= 9999) { int n1 = number; int n2 = n1 + increasingNumber; int n3 = n2 + increasingNumber; if (PrimeHelpers.IsPrimeNumber(n1) && PrimeHelpers.IsPrimeNumber(n2) && PrimeHelpers.IsPrimeNumber(n3)) { if (MathHelpers.IsPermutation(n1, n2) && MathHelpers.IsPermutation(n1, n3)) { result = MathHelpers.ConcatenateNumbers(new List <decimal> { n1, n2, n3 }); break; } } number++; } return(result); }
public static long NextPrime(long number) { while (true) { if (PrimeHelpers.IsPrimeNumber(number)) { return(number); } number++; } }
public static long SummationOfPrimes() { int number = 2000000; long summartionPrimes = 0; for (int i = 2; i < number; i++) { if (PrimeHelpers.IsPrimeNumber(i)) { summartionPrimes += i; } } return(summartionPrimes); }
static bool IsCricularPrimes(int primeNumber) { int circularNumber = MathHelpers.GetNextCircularNumber(primeNumber); while (circularNumber != primeNumber) { if (!PrimeHelpers.IsPrimeNumber(circularNumber)) { return(false); } circularNumber = MathHelpers.GetNextCircularNumber(circularNumber); } return(true); }
public static int Prime10001st() { int maxNumber = 10001; int numberOfPrime = 1; int prime = 1; while (numberOfPrime <= maxNumber) { prime += 1; if (PrimeHelpers.IsPrimeNumber(prime)) { numberOfPrime += 1; } } return(prime); }
public static long CircularPrimes() { int circularPrimesCount = 0; for (var i = 0; i < 1000000; i++) { if (PrimeHelpers.IsPrimeNumber(i)) { if (IsCricularPrimes(i)) { circularPrimesCount++; } } } return(circularPrimesCount); }
public static long TruncatablePrimes() { long result = 0; int count = 0; long primeNumber = 11; while (count < 11) { bool isFound = true; long left = primeNumber; long right = primeNumber; int length = MathHelpers.IntLength(left); while (length > 1) { length--; left /= 10; long rightPow = (long)Math.Pow(10, MathHelpers.IntLength(right) - 1); long digit = right / rightPow; right -= digit * rightPow; if (!PrimeHelpers.IsPrimeNumber(left) || !PrimeHelpers.IsPrimeNumber(right)) { isFound = false; break; } } if (isFound) { result += primeNumber; count++; } primeNumber = PrimeHelpers.GetNextPrime(primeNumber); } return(result); }
public static long QuadraticPrimes() { long result = 0; int maxPrimeCount = 0; for (int a = -1000; a <= 1000; a++) { for (int b = -1000; b <= 1000; b++) { int n = 0; while (PrimeHelpers.IsPrimeNumber(Math.Abs(n * n + a * n + b))) { n++; } if (n > maxPrimeCount) { maxPrimeCount = n; result = a * b; } } } return(result); }