aboutsummaryrefslogtreecommitdiff
path: root/challenge-156/eric-cheung/python/ch-1.py
blob: f03068bbac9ee9ec174e36acad47c7f8c8716514 (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
## Remarks
## https://www.geeksforgeeks.org/pernicious-number/
## Python program to print first nNum Pernicious Numbers

## Function to Check Prime Number
def isPrime(nInput):
    if nInput < 2:
        return False

    for nSubLoop in range(2, nInput):
        if not nInput % nSubLoop:
            return False

    return True


# Prints First nNum Pernicious Numbers
def printPernicious(nNum):

    nLoop, nCount = 1, 0

    while nCount < nNum:
        # "bin(nLoop).count('1')" Count No. of ones in Binary Representation
        if (isPrime(bin(nLoop).count('1'))):
            print(nLoop, end = ' ')
            nCount = nCount + 1

        nLoop = nLoop + 1

## Driver Code
nNum = 10
printPernicious(nNum)

## This Code is Contributed by Ansu Kumari