blob: d4fcaf7ebd80a94c0c898812f099be675925c577 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
## Remarks
## https://www.geeksforgeeks.org/additive-prime-number/
## Python3 Program For the Above Approach
## Check if nNum_01 is Prime or Not
def isPrime(nNum_01):
if (nNum_01 <= 1):
return False
if (nNum_01 <= 3):
return True
## This is Checked to Skip Middle Five Numbers
if (nNum_01 % 2 == 0 or nNum_01 % 3 == 0):
return False
nLoop = 5
while (nLoop * nLoop <= nNum_01):
if (nNum_01 % nLoop == 0 or nNum_01 % (nLoop + 2) == 0):
return False
nLoop = nLoop + 6
return True
## Function to Get Sum of Gigits
def getSum(nNum_02):
nSum = 0
while (nNum_02 != 0):
nSum = nSum + nNum_02 % 10
nNum_02 = int(nNum_02 / 10)
## Return the nSum of digits
return nSum
## Function to Check Whether the Given number is Additive Prime number or Not
def isAdditivePrime(nNum_03):
## If Number is not prime
if not isPrime(nNum_03):
return False
## print ("getSum(" + str(nNum_03) + "): " + str(getSum(nNum_03)))
## Check if Sum of Digits Is Prime or Not
return isPrime(getSum(nNum_03))
## Driver Code
## Given Number nInput
nInputLoop = 2
while (nInputLoop <= 100):
## Function Call
if (isAdditivePrime(nInputLoop)):
print (str(nInputLoop))
nInputLoop = nInputLoop + 1
## This code is contributed by Pratik Basu
|