-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem9.py
More file actions
40 lines (28 loc) · 1.04 KB
/
Problem9.py
File metadata and controls
40 lines (28 loc) · 1.04 KB
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
# Code by @AmirMotefaker
# projecteuler.net
# https://projecteuler.net/problem=9
# Special Pythagorean triplet
# Problem 9
# A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
# a**2 + b**2 = c**2
# For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2.
# There exists exactly one Pythagorean triplet for which a + b + c = 1000.
# Find the product abc.
import time
start_time = time.time() #Time at the start of program execution
for a in range(3, 1000):
for b in range (a + 1, 999):
c_Square = a**2 + b**2
c = c_Square**0.5
if a + b + c == 1000:
product = a * b * c
sum_a_b_c = a + b + c
print("a =", a)
print("b =", b)
print("c =", int(c))
print(a,"+",b,"+",int(c), "=", int(sum_a_b_c))
print("Product of a,b,c(a*b*c) =",int(product))
break
end_time = time.time() #Time at the end of execution
print ("Time of program execution:", (end_time - start_time)) # Time of program execution
### Answer: 31875000