일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 지오지브라
- 정오각형
- 시뮬레이션
- python
- counting sunday
- 프로젝트 오일러
- 리만합
- 구분구적법
- 하합
- 수학탐구
- Geogebra
- algeomath
- 상합
- 프랙탈
- 제곱근의뜻
- 큰수의법칙
- 이항분포
- 재귀함수
- 알지오매스
- 확률실험
- 작도
- 큰 수의 법칙
- 삼각함수의그래프
- 블록코딩
- 몬테카를로
- 파이썬
- project euler
- java
- 오일러
- 피타고라스 정리
Archives
- Today
- Total
이경수 선생님의 수학실험실
Problem 33(Digit cancelling fractions) 본문
Problem 33(Digit cancelling fractions)
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
In Python:
import time
import math
startTime = time.time()
numerator = 1
denominator = 1
for i in range(11, 100):
for j in range(10, i):
for n in range(0, 2):
if int(list(str(j))[1 - n]) == int(list(str(i))[n]) and int(list(str(i))[1 - n]) != 0:
if int(list(str(j))[n]) / int(list(str(i))[1 - n]) == j / i:
numerator *= j
denominator *= i
denominator /= math.gcd(numerator, denominator)
print(denominator)
print(time.time() - startTime, "seconds")
Run time: 0.02585887908935547 seconds
In Java:
package project_euler31_40;
import java.util.ArrayList;
public class Euler33 {
public static int findgcd(int i, int j) {
if (i < j) {
int temp = i;
i = j;
j = temp;
}
if (j == 0) {
return i;
} else {
return findgcd(j, i % j);
}
}
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int numerator = 1;
int denominator = 1;
String idata[];
String jdata[];
ArrayList<Integer> iList = new ArrayList<Integer>();
ArrayList<Integer> jList = new ArrayList<Integer>();
for (int i = 11; i < 100; i++) {
for (int j = 10; j < i; j++) {
String iStr = Integer.toString(i);
String jStr = Integer.toString(j);
iList.clear();
jList.clear();
idata = iStr.split("");
for (int k = 0; k < iStr.length(); k++) {
iList.add(Integer.parseInt(idata[k]));
}
jdata = jStr.split("");
for (int k = 0; k < jStr.length(); k++) {
jList.add(Integer.parseInt(jdata[k]));
}
for (int n = 0; n < 2; n++) {
if (iList.get(n) == jList.get(1 - n) && iList.get(1 - n) != 0) {
if ((double)jList.get(n) / iList.get(1 - n) == (double)j / i) {
numerator *= j;
denominator *= i;
}
}
}
}
}
denominator /= findgcd(numerator, denominator);
System.out.println(denominator);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 + "seconds");
}
}
Run time: 0.063seconds
Solution: 100
'Project Euler' 카테고리의 다른 글
Problem 35(Circular primes) (0) | 2019.06.04 |
---|---|
Problem 34(Digit factorials) (0) | 2019.06.02 |
Problem 32(Pandigital products) (0) | 2019.05.19 |
Problem 31(Coin sums) (0) | 2019.05.12 |
Problem 30(Digit fifth powers) (0) | 2019.05.12 |
Comments