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 static int Solve(long num) { var primes = PrimeNumbers.GetAllPrimes((int)Math.Sqrt(num)); var res = 1; for (var i = primes.Count - 1; i > 1; i--) { if (num % primes[i] == 0) { res = primes[i]; break; } } return(res); }
public static string Solve(int index) { var primes = PrimeNumbers.GetAllPrimes().Where(x => x > 1000 && x < 10000).ToList(); var primeStrings = primes.Select(x => x.ToString()).ToList(); var options = new List <List <int> >(); var considered = new HashSet <int>(); foreach (var p in primes) { if (considered.Contains(p)) { continue; } var perms = GetPermutations(p, primeStrings); perms.ForEach(x => considered.Add(x)); for (var a = 0; a < perms.Count; a++) { for (var b = a + 1; b < perms.Count; b++) { for (var c = b + 1; c < perms.Count; c++) { if (perms[c] - perms[b] == perms[b] - perms[a]) { options.Add(new List <int> { perms[a], perms[b], perms[c] }); a = perms.Count; b = perms.Count; c = perms.Count; } } } } } var res = options[index].Aggregate("", (c, n) => c + n.ToString()); return(res); }