def isPrime(num):
s=0
for j in range (1, num):
if(num%j==0):
s=s+1
if(s>1):
break
return(s)
a = 10**20;
b = 10**400;
for i in xrange(a, b):
if(isPrime(i)==1 and isPrime(sum(int(x) for x in str(i)))==1):
print('Sum of all digits of', i, 'is', sum(int(x) for x in str(i)))
My objective is to output all the numbers within 10^20 and 10^400 whose digits add up to a prime number in order to answer the question, "How many integers in the range [10^20, 10^400] exist such that the sum of their digits is a prime number?"
While googling around, I read that range would overflow and that xrange would be more efficient. When xrange was used, the error "OverflowError: Python int too large to convert to C long;" occurs.
How can I output the answer without error?