diff options
Diffstat (limited to 'challenge-171/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-171/eric-cheung/python/ch-1.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/challenge-171/eric-cheung/python/ch-1.py b/challenge-171/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..46ddebdd00 --- /dev/null +++ b/challenge-171/eric-cheung/python/ch-1.py @@ -0,0 +1,59 @@ +## Remarks
+from math import sqrt
+
+## Code to Find all the Factors of the Number Excluding the Number itself
+def getFactors(nInput):
+
+ ## Vector to Store the Factors
+ vectArr = []
+ vectArr.append(1)
+
+ ## Note that this Loop runs till sqrt(nInput)
+ for nSubLoop in range(2, int(sqrt(nInput)) + 1, 1):
+ ## if the value of nSubLoop is a factor
+ if (nInput % nSubLoop == 0):
+ vectArr.append(nSubLoop);
+
+ ## Condition to Check the Divisor is not the Number itself
+ if (int(nInput / nSubLoop) != nSubLoop):
+ vectArr.append(int(nInput / nSubLoop))
+
+ ## Return the Vector
+ return vectArr
+
+## Function to check if the number is Abundant or not
+def checkAbundant(nInput):
+ nSum = 0
+
+ ## Find the Divisors Using Function
+ vec = getFactors(nInput)
+
+ ## nSum All the Factors
+ for nSubLoop in range(len(vec)):
+ nSum = nSum + vec[nSubLoop]
+
+ ## Check for Abundant or Not
+ if (nSum > nInput):
+ return True
+
+ return False
+
+
+## Driver Code
+if __name__ == '__main__':
+
+ nLoop = 11
+ nCount = 0
+ arrAbundantNum = []
+
+ while nCount < 20:
+
+ if checkAbundant(nLoop):
+ arrAbundantNum.append(nLoop)
+ nCount = nCount + 1
+
+ nLoop = nLoop + 2
+
+ print (arrAbundantNum)
+
+## [945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925]
|
