Package-level declarations

Functions

Link copied to clipboard
fun areCoprime(first: Long, second: Long): Boolean

Two numbers are co-prime when the GCD of the numbers is 1. This method uses an algorithm called the Euclidean algorithm to compute GCD.

Link copied to clipboard
Link copied to clipboard
fun findFibonacciRecursive(n: Int, prev: Long = 1, current: Long = 1): Long
Link copied to clipboard
fun findGreatestCommonDivisor(first: Long, second: Long): Long

The method computes the greatest common divisor of two numbers by recursively applying the Euclidean algorithm: gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b)

Link copied to clipboard

The least common multiple is found out by using the principle that lcm(a, b) = (a * b) / gcd(a, b)

Link copied to clipboard

Generates a random prime number within range, using isPrime() function to check for primality.

Link copied to clipboard

Gets all primes until the limit by checking whether every number in the loop is a prime number.

Link copied to clipboard

Uses a method called sieve of Eratosthenes to get all prime numbers until the limit. Works by adding all the numbers in an arraylist first and then removing all the multiples of every single number in that list.

Link copied to clipboard
fun isPrime(num: Long): Boolean

This method returns true if the number is a prime number. Simply, it checks all the numbers up to the numbers square root and returns false if the number is divisible by any, otherwise returns true.

Link copied to clipboard
fun raiseToPower(num: Long, pow: Int): Long

Recursively raises a number to a certain power. This method returns the original number is power is 1, otherwise multiplies the number on the result of calling itself with decremented power. This means that the number will be multiplied on itself (the original) n amount of times, where n is the power.

Link copied to clipboard

Iteratively raises a number to a certain power. For description refer to the method above.

Link copied to clipboard
fun returnAllCoprimes(number: Long, limit: Long = number): List<Long>

Returns all co-primes starting from 1 of a number, where limit is the biggest number to be checked for coprimality.

Link copied to clipboard
fun returnClosestCoprimes(number: Long, amount: Int, increment: Boolean = false): List<Long>

Returns a specified amount of the closest co-primes in either direction from the number.