일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- algeomath
- Geogebra
- counting sunday
- 몬테카를로
- 피타고라스 정리
- 재귀함수
- 큰수의법칙
- 시뮬레이션
- 이항분포
- java
- 프랙탈
- 프로젝트 오일러
- 상합
- 지오지브라
- project euler
- 알지오매스
- 확률실험
- 파이썬
- 작도
- 제곱근의뜻
- 정오각형
- python
- 수학탐구
- 리만합
- 오일러
- 하합
- 큰 수의 법칙
- 구분구적법
- 삼각함수의그래프
- 블록코딩
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 39(Integer right triangles) 본문
Problem 39(Integer right triangles)
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
In Python:
import time
def ispythatriple(p, i, j):
if i ** 2 + j ** 2 == (p - (i + j)) ** 2:
return True
else:
return False
startTime = time.time()
maxCount = 0
maxP = 0
for p in range(3, 1001):
count = 0
for i in range(1, p // 3 + 1):
for j in range(i, (p - i) // 2 + 1):
if ispythatriple(p, i, j) is True:
count += 1
if count > maxCount:
maxCount = count
maxP = p
print(maxP)
print(time.time() - startTime, "seconds")
Run time: 36.53164219856262 seconds
In Java:
package project_euler31_40;
public class Euler39 {
public static Boolean ispythatriple(int p, int i, int j) {
if (Math.pow(i, 2) + Math.pow(j, 2) == Math.pow(p - (i + j), 2)){
return true;
}
return false;
}
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int count = 0;
int maxCount = 0;
int maxP = 0;
for (int p = 3; p < 1001; p++) {
count = 0;
for (int i = 1; i < Math.floorDiv(p, 3) + 1; i++) {
for (int j = i; j < Math.floorDiv(p - i, 2) + 1; j++) {
if (ispythatriple(p, i, j) == true) {
count ++;
}
}
}
if (count > maxCount) {
maxCount = count;
maxP = p;
}
}
System.out.println(maxP);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 + "seconds");
}
}
Run time: 0.14seconds
Solution: 840
'Project Euler' 카테고리의 다른 글
Problem 41(Pandigital prime) (0) | 2019.06.16 |
---|---|
Problem 40(Champernowne's constant) (0) | 2019.06.16 |
Problem 38(Pandigital multiples) (0) | 2019.06.15 |
Problem 37(Truncatable primes) (0) | 2019.06.06 |
Problem 36(Double-base palindromes) (0) | 2019.06.06 |
Comments