Add digits is prime or not
Problem to sum the digits and continue the same process until length become one. If final value is prime number print "YES". Otherwise print "NO".
Example-1:
Input : num = 123456 Output : YES Explain : 1+2+3+4+5+6 = 21 2 + 1 = 3.(It's prime number).
Example-2:
Input : num = 12345 Output : NO Explain : 1+2+3+4+5 = 15 1 + 5 = 6.(It's not a prime number).
Solution
num = 123456 if(num % 9 == 0 and num != 0): k = 9 else: k = num % 9 for i in range(2,k): if(k % i == 0): print("No") break else: print("Yes")
Output
Yes