일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Geogebra
- 제곱근의뜻
- 재귀함수
- 이항분포
- 삼각함수의그래프
- 프로젝트 오일러
- 큰수의법칙
- 몬테카를로
- 피타고라스 정리
- 파이썬
- counting sunday
- python
- 수학탐구
- 블록코딩
- 상합
- 알지오매스
- 오일러
- 큰 수의 법칙
- 하합
- 리만합
- 정오각형
- 지오지브라
- 구분구적법
- 작도
- project euler
- java
- algeomath
- 확률실험
- 시뮬레이션
- 프랙탈
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 40(Champernowne's constant) 본문
Problem 40(Champernowne's constant)
An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If \(d_{n}\) represents the nth digit of the fractional part, find the value of the following expression.
\(d_{1}\) × \(d_{10}\) × \(d_{100}\) × \(d_{1000}\) × \(d_{10000}\) × \(d_{100000}\) × \(d_{1000000}\)
In Python:
import time
startTime = time.time()
digitList = []
orderList = [1, 10, 10 ** 2, 10 ** 3, 10 ** 4, 10 ** 5, 10 ** 6]
product = 1
for n in range(1, 10 ** 6):
numList = list(str(n))
for num in numList:
digitList.append(int(num))
for order in orderList:
product *= digitList[order - 1]
print(product)
print(time.time() - startTime, "seconds")
Run time: 2.7522952556610107 seconds
In Java:
package project_euler31_40;
import java.util.ArrayList;
public class Euler40 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int product = 1;
int[] orderList = {1, 10, (int)Math.pow(10, 2),
(int)Math.pow(10, 3), (int)Math.pow(10, 4),
(int)Math.pow(10, 5), (int)Math.pow(10, 6)};
ArrayList<Integer> digitList = new ArrayList<Integer>();
String nStr = "";
String nData[];
for (int n = 1; n < (int)Math.pow(10, 6); n++) {
nStr = Integer.toString(n);
nData = nStr.split("");
for (int i = 0; i < nData.length; i++) {
digitList.add(Integer.parseInt(nData[i]));
}
}
for (int order : orderList) {
product *= digitList.get(order - 1);
}
System.out.println(product);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 + "seconds");
}
}
Run time: 1.571seconds
Solution: 210
'Project Euler' 카테고리의 다른 글
Problem 42(Coded triangle numbers) (0) | 2019.07.24 |
---|---|
Problem 41(Pandigital prime) (0) | 2019.06.16 |
Problem 39(Integer right triangles) (0) | 2019.06.16 |
Problem 38(Pandigital multiples) (0) | 2019.06.15 |
Problem 37(Truncatable primes) (0) | 2019.06.06 |
Comments