[🏆 Challenge 🏆] : Leyland numbers 🔢🏆🚨⚠💡🎮 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 25

[🏆 Challenge 🏆] : Leyland numbers 🔢🏆🚨⚠💡🎮

A Leyland number is a number which can be expressed as x^y + y^x. (here ^ stands for exponentiation). Also, both x and y need to be more than 1. Create a program that inputs a number and checks if it is Leyland or not and if it is then prints those 2 numbers also.

22nd Oct 2017, 4:30 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
29 Answers
+ 27
//here is my try ☺ ⬜🌹🌹🌹🌹🌹⬜ 🌹⬜⬜⬜⬜⬜⬜ 🌹⬜⬜⬜⬜⬜⬜ 🌹⬜⬜⬜🌹🌹🌹 🌹⬜⬜⬜⬜⬜🌹 🌹⬜⬜⬜⬜⬜🌹 ⬜🌹🌹🌹🌹🌹⬜ https://code.sololearn.com/cOAPoAQo1v1F/?ref=app
22nd Oct 2017, 6:32 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 21
yes ... can be equal to y
22nd Oct 2017, 7:13 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
22nd Oct 2017, 6:09 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 14
https://code.sololearn.com/cwT8AScmsXX7/?ref=app
22nd Oct 2017, 5:57 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 10
@Ga Yes. Natural numbers
22nd Oct 2017, 6:32 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 9
@Yash Thatte nice but, both x and y need to be greater than 1 so 2 is not Leyland.
22nd Oct 2017, 6:06 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
22nd Oct 2017, 9:20 PM
David Akhihiero
David Akhihiero - avatar
+ 8
@Gaurav Yes
22nd Oct 2017, 6:34 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 8
22nd Oct 2017, 8:05 PM
Maya
Maya - avatar
+ 8
@Kazi your code does not accept all Leyland numbers. Eg-100
23rd Oct 2017, 3:06 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 6
Can x be equal to y? I know it shouldn't be but if u express it mathematically then this should also be mentioned....
22nd Oct 2017, 6:55 PM
Infinity
Infinity - avatar
23rd Oct 2017, 2:59 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 5
@Shashank you have by mistake included #include <iostream> into your comment so your code gives error. Otherwise your code is correct.
25th Oct 2017, 1:11 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 5
Here is my solution. Basically brute force, but with smart limits set on the search space. [In particular, the largest that x or y can be is log2(N). And for a given x, you can stop looping over y values once x^y+y^x>N.] Works for any N up to at least 10^18 without timeout. https://code.sololearn.com/c3h3Kg4pyn8w/?ref=app
25th Oct 2017, 6:45 PM
Erik
22nd Oct 2017, 10:02 AM
Ferhat Sevim
Ferhat Sevim - avatar
22nd Oct 2017, 5:23 PM
Hiroki Masuda
Hiroki Masuda - avatar
+ 4
Here is my solution. Assuming that x can be equal to y. The real challenge is handling large numbers. https://code.sololearn.com/Wc818G695mQ1/?ref=app And since it would be boring if you input a wrong number, here is another one. https://code.sololearn.com/WGBx5MsI4zBt/?ref=app And if you do want to see more, try this one. Though you would have to wait. https://code.sololearn.com/Wy9APGl5xICj/?ref=app
23rd Oct 2017, 4:29 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
problem solved..@Swapnil
23rd Oct 2017, 3:38 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
23rd Oct 2017, 6:48 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
25th Oct 2017, 1:08 PM
Shashank Shekhar
Shashank Shekhar - avatar