File tree 4 files changed +115
-0
lines changed
4 files changed +115
-0
lines changed Original file line number Diff line number Diff line change
1
+ import math
2
+
3
+ allPythagoreanTriplets = []
4
+
5
+ def findPythagoreanTriplets (limit ):
6
+ c ,m = 0 ,2
7
+ global allPythagoreanTriplets
8
+
9
+ while c < limit :
10
+ for n in range (1 , m ):
11
+ a = m ** 2 - n ** 2
12
+ b = 2 * m * n
13
+ c = m ** 2 + n ** 2
14
+ allPythagoreanTriplets .append ([a ,b ,c ])
15
+ if a + b + c == limit :
16
+ return [a , b , c ]
17
+
18
+ m += 1
19
+
20
+
21
+ product = 1
22
+ for i in findPythagoreanTriplets (1000 ):
23
+ product *= i
24
+
25
+ print (product )
Original file line number Diff line number Diff line change
1
+ import math
2
+ import copy
3
+
4
+ # A function to print all prime factors of
5
+ # a given number n
6
+ def primeFactors (n ):
7
+ allPrimeFactors = [1 ]
8
+ temp = n
9
+ # Print the number of two's that divide n
10
+ while n % 2 == 0 :
11
+ allPrimeFactors .append (2 )
12
+ n = n // 2
13
+
14
+ # n must be odd at this point
15
+ # so a skip of 2 ( i = i + 2) can be used
16
+ for i in range (3 ,n + 1 ,2 ):
17
+
18
+ # while i divides n , print i ad divide n
19
+ while n % i == 0 :
20
+ allPrimeFactors .append (i )
21
+ n = n // i
22
+
23
+ # Condition if n is a prime
24
+ if len (allPrimeFactors ) == 1 :
25
+ allPrimeFactors .append (temp )
26
+ # number greater than 2
27
+ return allPrimeFactors
28
+
29
+
30
+ # print(primeFactors(17))
31
+ def smallestMultiple (n ):
32
+ factors = []
33
+ for i in range (3 , n + 1 ):
34
+ temp = copy .deepcopy (factors )
35
+ currfactors = primeFactors (i )
36
+ print (currfactors )
37
+ print (temp )
38
+ for i in currfactors :
39
+ if i in temp :
40
+ print (i )
41
+ temp .remove (i )
42
+ currfactors .remove (i )
43
+
44
+ for i in currfactors :
45
+ factors .append (i )
46
+
47
+ return factors
48
+
49
+
50
+ print (smallestMultiple (10 ))
Original file line number Diff line number Diff line change
1
+ def sumOfSquares (n ):
2
+ return n * (n + 1 )* (2 * n + 1 )/ 6
3
+
4
+
5
+ def squareOfSum (n ):
6
+ return pow (n * (n + 1 )/ 2 ,2 )
7
+
8
+
9
+ print (squareOfSum (100 ) - sumOfSquares (100 ))
Original file line number Diff line number Diff line change
1
+ import math
2
+
3
+ # A function to print all prime factors of
4
+ # a given number n
5
+ def primeFactors (n ):
6
+
7
+ # Print the number of two's that divide n
8
+ while n % 2 == 0 :
9
+ print (2 ),
10
+ n = n // 2
11
+
12
+ # n must be odd at this point
13
+ # so a skip of 2 ( i = i + 2) can be used
14
+ for i in range (3 ,int (math .sqrt (n ))+ 1 ,2 ):
15
+
16
+ # while i divides n , print i ad divide n
17
+ while n % i == 0 :
18
+ print (i ),
19
+ n = n // i
20
+
21
+ # Condition if n is a prime
22
+ # number greater than 2
23
+ if n > 2 :
24
+ print (n )
25
+
26
+ # Driver Program to test above function
27
+
28
+ n = 6
29
+ primeFactors (n )
30
+
31
+ # This code is contributed by Harshit Agrawal
You can’t perform that action at this time.
0 commit comments