| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- 재귀함수
- 상합
- 수학탐구
- 큰수의법칙
- 오일러
- 큰 수의 법칙
- 몬테카를로
- counting sunday
- python
- 삼각함수의그래프
- 리만합
- 구분구적법
- 이항분포
- 블록코딩
- 제곱근의뜻
- 파이썬
- 피타고라스 정리
- 지오지브라
- algeomath
- 프랙탈
- 프로젝트 오일러
- 작도
- 확률실험
- java
- 하합
- Geogebra
- 정오각형
- project euler
- 시뮬레이션
- 알지오매스
- Today
- Total
이경수 선생님의 수학실험실
Problem 5(Smallest multiple) 본문
Problem 5(Smallest multiple)
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
In Python:
import time
startTime = time.time()
multiple = 1
temp = 0
for i in range(2, 21):
for j in range(2, i+1):
temp = multiple
while i % j == 0:
i = i / j
if temp % j == 0:
temp = temp / j
else:
multiple = multiple * j
print(multiple)
print(time.time() - startTime, "seconds")
In Java:
package project_euler;
public class Euler5 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int multiple = 1;
int temp = 0;
int k = 0;
for (int i = 2; i < 21; i++) {
k = i;
for (int j = 2; j < i + 1; j++) {
temp = multiple;
while (k % j == 0) {
k = k / j;
if (temp % j == 0) {
temp = temp / j;
}
else {
multiple = multiple * j;
}
}
}
}
System.out.println(multiple);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 +"seconds");
System.out.println(endTime - startTime +"ms");
}
}
solution: 232792560
[from Project Euler: https://projecteuler.net/problem=5]
'Project Euler' 카테고리의 다른 글
| Problem 7(10001st prime) (0) | 2019.02.08 |
|---|---|
| Problem 6(Sum square difference) (0) | 2019.02.08 |
| Problem 4(Largest palindrome product) (0) | 2019.02.07 |
| Problem 3(Largest prime factor) (0) | 2019.02.06 |
| Problem 2(Even Fibonacci numbers) (0) | 2019.02.06 |