Challenge: Crazy Number | Sololearn: Learn to code for FREE!

+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)) */

12/9/2017 2:12:30 AM

Я. ♨

109 Answers

New Answer

+2

Go for this challenge too https://www.sololearn.com/Discuss/909996/challenge-rorrim-it

+15

https://code.sololearn.com/cFrXtgp3ayZy/?ref=app (but this only checks for cubes)

+15

https://code.sololearn.com/cKw15aU62wuj/?ref=app

+13

Here's : https://code.sololearn.com/c33X1EAmH5TU/?ref=app

+13

@Zeel Patel 24678050 and 24678051. In fact if a crazy number ends with zero the next number is also crazy!

+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

+12

you can check them using my Java code

+12

can anyone tell me where is mistake... https://code.sololearn.com/cGUADS7M504y/?ref=app

+11

Here's mine. First C code at SL!! https://code.sololearn.com/c5qmjqRXG7Ta/?ref=app

+10

https://code.sololearn.com/cnhB8r2eefTU/?ref=app

+9

@Zeel Patel thats not true you can find other examples using my C++ code. run my code for 100000000

+9

Here's my try in Python according to your specified input and output. https://code.sololearn.com/cgcFv51Gm1O3/?ref=app

+8

https://code.sololearn.com/cdkYWk9D5YuZ/?ref=app

+8

Mine in python https://code.sololearn.com/cc7fPStE63NI/?ref=app

+8

My try https://code.sololearn.com/cTdvu2B5JcHQ/?ref=app

+8

@Rajesh Kumar Done

+7

Here's mine https://code.sololearn.com/cwCzoLdv6vvD/?ref=app

+7

CHALLENGE ACCEPTED Weapon : C++ https://code.sololearn.com/c4R7SitJ6v23/?ref=app

+7

@Rajesh i updated my version to 1.0 plzz check it soon https://code.sololearn.com/c2ObSc3bH9FS/?ref=app

+7

you can change 1634by any other number