After reading Uncle Petros and Goldbach's Conjecture, I wanted to write a program that would break an even number into two primes. However, I also decided to add functionalities like prime tests and my favourite functionality of all time - Real Random Generator (here: Real Random Prime Generator).
Part one: Primality Test
Depending on the size of the input string, two algorithms were implemented:
If the input string can be parsed into a long type, the following method was used:
If not, the input was cast into a BigInteger type and the following method was used:
This way. the app can take care of any input size.
Part two: Goldbach's prime pair
According to the famous Goldbach's Conjecture, Every even integer greater than 2 can be expressed as the sum of two primes. This part of the app allows the users to break an even number into two primes. If the input is less than or equal to 50000, it will also list all distinct sum of two prime that make up the number. Using Sieve of Eratosthenes and looping through n/2 number of primes before the input, if prime+x=input, where x is another prime was satisfied, a pair (prime, x) would satisfy Goldbach's conjecture.
Part three: Random Prime Generator
This part of the app allows users to generate random primes. Prime number less than a million was stored in a String array. Then the index of the array was randomly generated. If the user's device has an active internet connection, the user can choose to generate a real random prime number. The index for the real random prime number was imported from Random.org's integer generator.