Leyland Number | Javascript program to print first N Leyland Numbers . ; Print first n Leyland Number . ; Outer loop for x from 2 to n . ; Inner loop for y from 2 to x . ; Calculating x ^ y + y ^ x ; Sorting the all Leyland Number . ; Printing first n Leyland number . ; Driver Code
let MAX = 100 ; function leyland ( n ) { let ans = [ ] ; let index = 0 ; for ( let x = 2 ; x <= n ; x ++ ) { for ( let y = 2 ; y <= x ; y ++ ) { let temp = Math . pow ( x , y ) + Math . pow ( y , x ) ; ans [ index ] = temp ; index ++ ; } } console . log ( ans ) ans = ans . sort ( ( a , b ) => a - b ) ; console . log ( ans ) for ( let i = 0 ; i < n ; i ++ ) document . write ( ans [ i ] + " " ) ; } let n = 6 ; leyland ( n ) ;