Leyland Number | Python3 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
import math NEW_LINE def leyland ( n ) : NEW_LINE INDENT ans = [ ] NEW_LINE x = 2 NEW_LINE y = 2 NEW_LINE while x <= n : NEW_LINE INDENT y = 2 NEW_LINE while y <= x : NEW_LINE INDENT temp = pow ( x , y ) + pow ( y , x ) NEW_LINE ans . append ( temp ) ; NEW_LINE y = y + 1 NEW_LINE DEDENT x = x + 1 NEW_LINE DEDENT ans . sort ( ) ; NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT print ( ans [ i ] , end = " ▁ " ) NEW_LINE i = i + 1 NEW_LINE DEDENT DEDENT n = 6 NEW_LINE leyland ( n ) NEW_LINE