Wheel Factorization Algorithm | Function to check if a given number x is prime or not ; The Wheel for checking prime number ; Base Case ; Check for the number taken as basis ; Check for Wheel Here i , acts as the layer of the wheel ; Check for the list of Sieve in arr [ ] ; If number is greater than sqrt ( N ) break ; Check if N is a multiple of prime number in the wheel ; If at any iteration isPrime is false , break from the loop ; Driver 's Code ; Function call for primality check
function isPrime ( N ) { let isPrime = true ; let arr = [ 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 ] ; if ( N < 2 ) { isPrime = false ; } if ( N % 2 == 0 N % 3 == 0 N % 5 == 0 ) { isPrime = false ; } for ( let i = 0 ; i < Math . sqrt ( N ) ; i += 30 ) { for ( let c of arr ) { if ( c > Math . sqrt ( N ) ) { break ; } else { if ( N % ( c + i ) == 0 ) { isPrime = false ; break ; } } if ( ! isPrime ) break ; } } if ( isPrime ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 121 ; isPrime ( N ) ;