File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Problem statement and Explanation : https://en.wikipedia.org/wiki/Coprime_integers
3+
4+ In number theory, two integers a and b are coprime, relatively prime or
5+ mutually prime if the only positive integer that is a divisor of both
6+ of them is Consequently, any prime number that divides one of a
7+ or b does not divide the other. This is equivalent to their greatest
8+ common divisor (gcd) being. One says also a is prime to b or a
9+ is coprime with b.
10+ */
11+
12+ // Here we require an already implemented method.
13+ const GetEuclidGCD = require ( './GetEuclidGCD' )
14+
15+ // CoPrimeCheck function return the boolean in respect of the given number is co-prime or not.
16+ /**
17+ * CoPrimeCheck function return the boolean in respect of the given number is co-prime or not.
18+ * @param {Number } firstNumber first number for checking is prime or not.
19+ * @param {Number } secondNumber second number for checking is prime or not.
20+ * @returns return correspond boolean value, if both number are co-prime return `true`, else return `false`.
21+ */
22+ const CoPrimeCheck = ( firstNumber , secondNumber ) => {
23+ /*
24+ This is the most efficient algorithm for checking co-primes
25+ if the GCD of both the numbers is 1 that means they are co-primes.
26+ */
27+ return GetEuclidGCD ( firstNumber , secondNumber ) === 1
28+ }
29+
30+ module . exports = CoPrimeCheck
You can’t perform that action at this time.
0 commit comments