public static int truncatableprimes(int n) { int count = 0; int sum = 0; PrimeFunctions.GeneratePrimesToList(1000000); PrimeFunctions.ConvertToHash(); int i = 4; while (count < n) { bool isprime = true; List <int> trunc = CombinatoricFunctions.truncations(PrimeFunctions.PrimeList[i]); foreach (int truncation in trunc) { if (!PrimeFunctions.PrimeListHash.Contains(truncation)) { isprime = false; break; } } if (isprime) { count++; sum += PrimeFunctions.PrimeList[i]; } i++; } return(sum); }
public static int SmallestMultiple(int n) { PrimeFunctions.GeneratePrimesTillNToList(n); List <int> FactorList = new List <int>(); //Loop until highest multiple for (int i = 2; i <= n; i++) { //Find all the factors of the number List <int> factors = PrimeFunctions.PrimeFactor(i, false); //If the list of factors doesn't contain the factor or as many factors, then add it to the list foreach (int factor in factors) { if (MiscFunctions.ReturnDistinctCountList(factors, factor) > MiscFunctions.ReturnDistinctCountList(FactorList, factor)) { FactorList.Add(factor); } } } //Loop through the minimum required factors and multiply them all int mult = 1; foreach (int factor in FactorList) { mult *= factor; } return(mult); }
public static int CirculuarPrimes(int n) { PrimeFunctions.GeneratePrimesTillNToList(1000000); PrimeFunctions.ConvertToHash(); int count = 0; for (int i = 2; i < n; i++) { List <int> rots = CombinatoricFunctions.rotations(i); bool prime = true; foreach (int rot in rots) { if (!PrimeFunctions.PrimeListHash.Contains(rot)) { prime = false; break; } } if (prime) { count++; //Console.WriteLine(i); } } return(count); }
public static long SummationOfPrimes(int n) { List <int> primes = PrimeFunctions.GeneratePrimesTillN(2 * n); long k = 0; for (int i = 0; primes[i] < n; i++) { k += primes[i]; } return(k); }
public static int PandigitalPrime(int n) { List <int> PanPrimes = new List <int>(); PrimeFunctions.GeneratePrimesTillNToList(n); for (int i = 0; i < PrimeFunctions.PrimeList.Count; i++) { if (MiscFunctions.IsPandigital(PrimeFunctions.PrimeList[i])) { PanPrimes.Add(PrimeFunctions.PrimeList[i]); } } return(PanPrimes.Max()); }
public static int OddComposite() { int comp = 0; List <int> primes = PrimeFunctions.GeneratePrimes(10000); HashSet <int> primeshash = MiscFunctions.ListToHash(primes); List <int> squares = SpecialSequences.squares(1000); HashSet <int> squareshash = MiscFunctions.ListToHash(squares); int i = 3; bool found = false; while (comp == 0) { found = false; i += 2; if (primeshash.Contains(i)) { continue; } for (int j = 0; j < primes.Count; j++) { if (primes[j] > i) { break; } for (int k = 0; k < squares.Count; k++) { if (squares[k] * 2 > i) { break; } if (primes[j] + (squares[k] * 2) == i) { found = true; } } } if (!found) { comp = i; } } return(comp); }
public static int DistinctPrimeFactors() { PrimeFunctions.GeneratePrimesToList(100000); int i = 2; int count = 0; while (count < 4) { i++; List <int> primes = PrimeFunctions.PrimeFactor(i); HashSet <int> factors = MiscFunctions.ListToHash(primes); if (factors.Count == 4) { count++; } else { count = 0; } } return(i - 3); }
public static int QuadraticPrimes(int n) { PrimeFunctions.GeneratePrimesTillNToList(n * n); PrimeFunctions.ConvertToHash(); int maxi = 0; int maxj = 0; int maxprimes = 0; for (int i = (n * -1); i < n; i++) { for (int j = (n * -1); j < n; j++) { if (numquadprimes(i, j) > maxprimes) { maxprimes = numquadprimes(i, j); maxi = i; maxj = j; } } } return(maxi * maxj); }
public static int LargestPrimeFactor(long n) { //Return the largest number in the list of prime factors return(PrimeFunctions.PrimeFactor(n).Max()); }
public static int TenthousandstPrime(int n) { return(PrimeFunctions.NthPrime(n)); }