Challenge: Crazy Number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 38

Challenge: Crazy Number

An Crazy number is an n-digit positive number such that the sum of its digits raised to the power n is the number itself. Write a program to check whether a number is Crazy number or not. If number is a Crazy number, print "Yes" else "No". See sample test case given below for more clarification. N.B: We are assuming all numbers given are in base 10. Input Specification: First input is an interger t denotes number of test cases. Next there will be t lines denoting t test cases. Each test case line will have a number N for which you have to check whether it is Crazy Number of not. Output Specification: Output contains t lines. ith line output will be either "Yes" or "No" depending on the number in ith test case. Constraints: 0 < t < 2^31 0 < N < 2^63 Sample Input: 3 153 12 1634 Sample Output: Yes No Yes Explanation: There are three test cases. First testcase: 153 is a 3 digit number. So 1^3 + 5^3 + 3^3 = = 1 + 125 + 27 = 153. So, 157 is Crazy number. Second testcase: 12 is a 2 digit number. So 1^2 + 2^2 = 1 + 4 = 5 != 12. So, 12 is not a Crazy number. Third testcase: 1634 is a 4 digit number. So 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634. So, 1634 is a Crazy number. Hence the ouput is : Yes No Yes My Program: https://code.sololearn.com/cXme4sSLqqfu/#java /* Edit: Except few peoples everyone else write code for just a simple Armstrong Number Checker. All you need to read the question again specially the Input/output Specifications. and few coders like @Dipta @Rame#1 @Reniel @Yerucham @LukArToDo writes code according to input/output specication but only few of them passes this case ((Constraints: 0 < t < 2^31 0 < N < 2^63)) */

9th Dec 2017, 2:12 AM
Я. ♨
Я. ♨ - avatar
103 Answers
9th Dec 2017, 2:33 PM
Я. ♨
Я. ♨ - avatar
+ 15
https://code.sololearn.com/cFrXtgp3ayZy/?ref=app (but this only checks for cubes)
7th Dec 2017, 1:34 PM
David Ashton
David Ashton - avatar
8th Dec 2017, 6:23 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
7th Dec 2017, 4:09 PM
LukArToDo
LukArToDo - avatar
+ 13
@Zeel Patel 24678050 and 24678051. In fact if a crazy number ends with zero the next number is also crazy!
9th Dec 2017, 11:44 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 12
I have done it using Java and C++. My Java code answers whether the entered number is crazy. But my C++ code lists all crazy numbers less than or equal the entered number. Here are my answers: https://code.sololearn.com/ckmra6Z601wV https://code.sololearn.com/cOXr2142DPqR
8th Dec 2017, 8:47 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 12
you can check them using my Java code
9th Dec 2017, 11:45 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 12
can anyone tell me where is mistake... https://code.sololearn.com/cGUADS7M504y/?ref=app
9th Dec 2017, 1:37 PM
Vukan
Vukan - avatar
+ 11
Here's mine. First C code at SL!! https://code.sololearn.com/c5qmjqRXG7Ta/?ref=app
8th Dec 2017, 12:37 PM
Infinity
Infinity - avatar
+ 10
https://code.sololearn.com/cnhB8r2eefTU/?ref=app
11th Dec 2017, 10:28 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 9
@Zeel Patel thats not true you can find other examples using my C++ code. run my code for 100000000
9th Dec 2017, 11:28 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 9
Here's my try in Python according to your specified input and output. https://code.sololearn.com/cgcFv51Gm1O3/?ref=app
10th Dec 2017, 12:42 PM
Kartik
Kartik - avatar
+ 8
https://code.sololearn.com/cdkYWk9D5YuZ/?ref=app
8th Dec 2017, 5:07 AM
David Ashton
David Ashton - avatar
8th Dec 2017, 6:06 AM
Louis
Louis - avatar
8th Dec 2017, 8:13 PM
David Akhihiero
David Akhihiero - avatar
+ 8
@Rajesh Kumar Done
10th Dec 2017, 3:19 PM
Kartik
Kartik - avatar
8th Dec 2017, 3:35 PM
Glitched
Glitched - avatar
+ 7
CHALLENGE ACCEPTED Weapon : C++ https://code.sololearn.com/c4R7SitJ6v23/?ref=app
8th Dec 2017, 7:21 PM
Qwqwq Rt
Qwqwq Rt - avatar
+ 7
@Rajesh i updated my version to 1.0 plzz check it soon https://code.sololearn.com/c2ObSc3bH9FS/?ref=app
9th Dec 2017, 2:02 AM
SAKSHI
SAKSHI - avatar
+ 7
you can change 1634by any other number
10th Dec 2017, 3:00 PM
Arun