티스토리 뷰
A Pythagorean triple consists of three strictly positive integers , and , for which . The name is derived from the Pythagorean theorem, stating that every right triangle has side lengths satisfying the formula . Thus, Pythagorean triples describe the three integer side lengths of a right triangle. However, right triangles with non-integer sides do not form Pythagorean triples.
A well-known example of a Pythagorean triple is , but also its multiples such as and are Pythagorean triples. In general, if is a Pythagorean triple, then so is for any positive integer . A primitive Pythagorean triple is one in which , and are coprime. As an example, there are four Pythagorean triples for which : , , and .
Pythagorean triples have been known since ancient times. Babylonian clay tablets dating from the time of Hammurabi already mention Pythagorean triples. The oldest known record comes from Plimpton 322, a Babylonian clay tablet from about 1800BC, written in a sexagesimalnumber system. It was discovered by Edgar James Banks shortly after 1900, and sold to George Arthur Plimpton in 1922 for $10. This clay tablet lists 15 triplets, including , and even . Pythagorean triples were also known in India. The earliest Baudhayana-Sulbasutra (dating back to the sixth century before Christ) contains five such triples.
Input
A number .
Output
A list of all Pythagorean triples for which and . These triples must be written as (a, b, c), each on a separate line and sorted in increasing order according to , then and then .
Example
Input:
240
Output:
(15, 112, 113)(40, 96, 104)(48, 90, 102)(60, 80, 100)
ver. latest
def check_triple(a, b, c, num):
cond_pytha = a * a + b * b == c * c
cond_sum = a + b + c == num
if cond_pytha and cond_sum:
return True
return False
def pick_triple(a, b, c, num):
if a < b < c:
if check_triple(a, b, c, num):
print("({}, {}, {})".format(a, b, c))
def get_triple(num):
half = int(num / 2)
for a in range(1, half):
for b in range(half - a, half):
for c in range(num - (a + b), half):
pick_triple(a, b, c, num)
get_triple(int(input()))
def check_pythagorean(a, b, c):
if a * a + b * b == c * c:
return True
else:
return False
def pick_triple(a, b, c, num, triples):
if a < b < c:
if a + b + c == num:
if check_pythagorean(a, b, c):
triples.append((a, b, c))
def get_pythagorean(num):
triples = list()
half = int(num / 2)
for a in range(1, half):
for b in range(half - a, half):
for c in range(num - (a + b), half):
pick_triple(a, b, c, num, triples)
show(triples)
def show(triples):
for triple in triples:
print(triple)
get_pythagorean(int(input()))
'python lecture > algorism' 카테고리의 다른 글
[eud] Cowsay (0) | 2018.10.02 |
---|---|
[edu] Wepe speapeak p (0) | 2018.10.02 |
[edu] Monkeys and coconuts (0) | 2018.10.02 |
[edu] 성능 시작측정 코드(decorator, prime, 소수) (0) | 2018.08.27 |
[edu] 소수 구하기 (0) | 2018.08.27 |
- Total
- Today
- Yesterday
- 엑셀 비교
- 면접답변
- virtualenv
- admin.py
- 파이썬 프로그래밍
- gitignore
- gitlab
- 모바일 스킨 적용
- 파이썬
- 이미지 비교
- 면접정답
- 파이썬 강좌
- 파이썬 입문
- 장고 카톡 자동응답
- 문서 비교
- django chatbot
- pycrypto
- 문과 코딩
- 모바일 테마 적용
- GIT
- 파이썬 독학
- Tistory
- django
- chatbot
- 장고
- 장고 플러스친구 자동응답
- wsgi
- 플러스친구 자동응답
- Python
- PuTTYGen
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |