public void ListPrime() { ArrayList centList = Primes.Generate(100); Assert.AreEqual(25, centList.Count); Assert.AreEqual(97, centList[24]); }
public void ListSingle() { ArrayList primes = Primes.Generate(2); Assert.AreEqual(1, primes.Count); Assert.IsTrue(primes.Contains(2)); }
public void ListBasic() { ArrayList primes = Primes.Generate(knownPrimes[knownPrimes.Length - 1]); Assert.AreEqual(knownPrimes.Length, primes.Count); int i = 0; foreach (int prime in primes) { Assert.AreEqual(knownPrimes[i++], prime); } }
protected override void Solve() { // Limit of 15 digits at max value. ulong inputLimit = 999999999999999; ulong input = Input.RequestULong(Prompt + " The limit is 15 digits.", inputLimit); int root = (int)Math.Sqrt(input); int[] primes = Primes.Generate(root); List <int> factors = new List <int>(); int high = 0; foreach (int i in primes) { if (input % (ulong)i == 0) { factors.Add(i); high = i; } } if (factors.Count > 1) { string str = StringSerialize.StringListFromInts(factors.ToArray()); Console.WriteLine("\n" + str + "\n"); Console.WriteLine($"There are {factors.Count} prime factors for the number {input}, listed above."); Console.WriteLine($"Therefore, the largest prime factor of {input} is {high}.\n"); } else if (factors.Count == 1) { Console.WriteLine($"\nThere is only one prime factor for the number {input}, it is {factors[0]}"); Console.WriteLine($"Therefore, the largest prime factor of {input} is {high}.\n"); } else { Console.WriteLine($"\nThe number {input} is prime itself!"); Console.WriteLine("Therefore, its highest prime factor is itself!\n"); } int x = Input.RequestInt(".."); int[] y = Primes.Generate(x); Console.WriteLine($"The largest index generated from {x} is {y.Length}."); }
public void ListLots() { int bound = 10101; ArrayList primes = Primes.Generate(bound); foreach (int prime in primes) { Assert.IsTrue(IsPrime(prime), "is prime"); } foreach (int prime in primes) { if (IsPrime(prime)) { Assert.IsTrue(primes.Contains(prime), "contains primes"); } else { Assert.IsFalse(primes.Contains(prime), "doesn't contain composites"); } } }
public object BigPrime(int digits, CancellationToken cToken) { return(new { prime = Primes.Generate(digits, cToken).ToString("N0") }); }
public void ListZero() { ArrayList primes = Primes.Generate(0); Assert.AreEqual(0, primes.Count); }
public void ZeroOne() { ArrayList primes = Primes.Generate(1); Assert.AreEqual(0, primes.Count); }