일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 확률실험
- 이항분포
- 피타고라스 정리
- 재귀함수
- 삼각함수의그래프
- python
- 수학탐구
- 리만합
- 시뮬레이션
- counting sunday
- 프로젝트 오일러
- 상합
- project euler
- 하합
- 오일러
- 블록코딩
- 알지오매스
- 작도
- 지오지브라
- 정오각형
- 파이썬
- 프랙탈
- 큰 수의 법칙
- algeomath
- Geogebra
- 구분구적법
- 큰수의법칙
- 제곱근의뜻
- java
- 몬테카를로
- Today
- Total
이경수 선생님의 수학실험실
Problem 7(10001st prime) 본문
Problem 7(10001st prime)
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
In Python:
# PE7 10001st prime
import time
import math
startTime = time.time()
order = 1
num = 1
def is_prime(n):
if n == 1:
return False
elif n == 2:
return True
else:
i = 2
while i < math.ceil(math.sqrt(n)) + 1:
if n % i == 0:
return False
else:
i += 1
return True
while order < 10001:
num += 2
if is_prime(num):
order += 1
else:
continue
print(num)
print(time.time() - startTime, "seconds")
Run time: 1.2066988945007324 seconds
In Java:
//Euler7 10001st prime
package project_euler;
public class Euler7 {
public static boolean isPrime(int n) {
if (n == 1) {
return false;
}
else if (n == 2) {
return true;
}
else {
int i = 2;
while (i < Math.ceil(Math.sqrt(n))+1) {
if (n % i == 0) {
return false;
}
else {
i += 1;
}
}
return true;
}
}
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int num = 1;
int order = 1;
while (order < 10001) {
num += 2;
if (isPrime(num)) {
order += 1;
}
else {
continue;
}
}
System.out.println(num);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime) / (double)1000 + "seconds");
}
}
Run time: 0.048seconds
solution: 104743
[from Project Euler: https://projecteuler.net/problem=7]
'Project Euler' 카테고리의 다른 글
Problem 9(Special Pythagorean triplet) (0) | 2019.02.09 |
---|---|
Problem 8(Largest product in a series) (0) | 2019.02.09 |
Problem 6(Sum square difference) (0) | 2019.02.08 |
Problem 5(Smallest multiple) (0) | 2019.02.08 |
Problem 4(Largest palindrome product) (0) | 2019.02.07 |