HACKER RANK Project Euler 16 - Power Digit Sum - Solution.'Rb'

Project Euler Challenges-16 - Power Digit Sum Solution
Problem Statement
This problem is a programming version of Problem 16 from projecteuler.net
29=512 and the sum of its digits is 5+1+2=8.
What is the sum of the digits of the number 2N ?
Input Format 
The first line contains an integer T , i.e., number of test cases. 
Next T lines will contain an integer N.
Output Format 
Print the values corresponding to each test case.
Constraints 
1T100 
1N104 
Sample Input
3
3
4
7
Sample Output
8
7
11

Solution:

# Enter your code here. Read input from STDIN. Print output to STDOUT
a=gets
for i in 0...a.to_i
b=gets
b=2**b.to_i
#print b.to_i
#print "\n"
while b.to_i>0 do
c=b.to_i%10
#print c
d= d.to_i + c.to_i
b=b.to_i/10
end
print d.to_i
print "\n";
d=0;
end

Thanks for Visiting, Hope this helps you....

Comments

Popular Posts