일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 이항분포
- 확률실험
- 하합
- 프랙탈
- counting sunday
- 지오지브라
- 구분구적법
- 제곱근의뜻
- 작도
- 알지오매스
- Geogebra
- 재귀함수
- 블록코딩
- 정오각형
- java
- 큰수의법칙
- 몬테카를로
- 파이썬
- 프로젝트 오일러
- 피타고라스 정리
- 수학탐구
- 삼각함수의그래프
- 시뮬레이션
- algeomath
- 오일러
- 큰 수의 법칙
- project euler
- 리만합
- python
- 상합
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 28(Number spiral diagonals) 본문
Problem 28(Number spiral diagonals)
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
21 | 22 | 23 | 24 | 25 |
20 | 7 | 8 | 9 | 10 |
19 | 6 | 1 | 2 | 11 |
18 | 5 | 4 | 3 | 12 |
17 | 16 | 15 | 14 | 13 |
It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
In Python:
import time
startTime = time.time()
sumDiagonals = 1
i = 1
numFirst = [4 * n ** 2 -2 * n + 1 for n in range(1, 501)]
for n in numFirst:
subList = [n, n + 2 * i, n + 4 * i, n + 6 * i]
sumDiagonals += sum(subList)
i += 1
print(sumDiagonals)
print(time.time() - startTime, "seconds")
Run time: 0.0018131732940673828 seconds
In Java:
package project_euler21_30;
import java.util.ArrayList;
public class Euler28 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int sumDiagonals = 1;
int i = 1;
ArrayList<Integer> numFirst = new ArrayList<Integer>();
for (int n = 1; n < 501; n++) {
numFirst.add(4 * (int)Math.pow(n, 2) - 2 * n + 1);
}
for (Integer n : numFirst) {
sumDiagonals += 4 * n + 12 * i;
i++;
}
System.out.println(sumDiagonals);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 + "seconds");
}
}
Run time: 0.001seconds
Solution: 669171001
'Project Euler' 카테고리의 다른 글
Problem 30(Digit fifth powers) (0) | 2019.05.12 |
---|---|
Problem 29(Distinct powers) (0) | 2019.05.12 |
Problem 27(Quadratic primes) (0) | 2019.05.12 |
Problem 26(Reciprocal cycles) (0) | 2019.05.11 |
Problem 25(1000-digit Fibonacci number) (0) | 2019.05.11 |
Comments