일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 몬테카를로
- 확률실험
- 파이썬
- 수학탐구
- Geogebra
- counting sunday
- java
- 구분구적법
- python
- 하합
- 시뮬레이션
- 프랙탈
- project euler
- 정오각형
- 리만합
- algeomath
- 알지오매스
- 상합
- 피타고라스 정리
- 큰수의법칙
- 이항분포
- 작도
- 제곱근의뜻
- 오일러
- 지오지브라
- 삼각함수의그래프
- 블록코딩
- 큰 수의 법칙
- 재귀함수
- 프로젝트 오일러
- 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 |