Problem 71 » 履歴 » バージョン 2
Noppi, 2024/02/01 07:24
1 | 1 | Noppi | [ホーム](https://redmine.noppi.jp) - [[Wiki|Project Euler]] |
---|---|---|---|
2 | # [[Problem 71]] |
||
3 | |||
4 | ## Ordered Fractions |
||
5 | Consider the fraction, $\dfrac n d$, where $n$ and $d$ are positive integers. If $n \lt d$ and $\operatorname{HCF}(n,d)=1$, it is called a reduced proper fraction. |
||
6 | |||
7 | If we list the set of reduced proper fractions for $d \le 8$ in ascending order of size, we get: |
||
8 | $$\frac 1 8, \frac 1 7, \frac 1 6, \frac 1 5, \frac 1 4, \frac 2 7, \frac 1 3, \frac 3 8, \mathbf{\frac 2 5}, \frac 3 7, \frac 1 2, \frac 4 7, \frac 3 5, \frac 5 8, \frac 2 3, \frac 5 7, \frac 3 4, \frac 4 5, \frac 5 6, \frac 6 7, \frac 7 8$$ |
||
9 | |||
10 | It can be seen that $\dfrac 2 5$ is the fraction immediately to the left of $\dfrac 3 7$. |
||
11 | |||
12 | By listing the set of reduced proper fractions for $d \le 1\,000\,000$ in ascending order of size, find the numerator of the fraction immediately to the left of $\dfrac 3 7$. |
||
13 | |||
14 | ## 順序分数 |
||
15 | nとdを正の整数として, 分数 n/d を考えよう. n<d かつ HCF(n,d)=1 のとき, 真既約分数と呼ぶ. |
||
16 | |||
17 | d ≤ 8について既約分数を大きさ順に並べると, 以下を得る: |
||
18 | |||
19 | <div style="text-align:center">1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, <b>2/5</b> , 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8</div> |
||
20 | |||
21 | 3/7のすぐ左の分数は2/5である. |
||
22 | |||
23 | d ≤ 1,000,000について真既約分数を大きさ順に並べたとき, 3/7のすぐ左の分数の分子を求めよ. |
||
24 | |||
25 | ```scheme |
||
26 | 2 | Noppi | (import (scheme base) |
27 | (gauche base)) |
||
28 | |||
29 | ;;; ファレイ数列の性質から、3/7 の左隣は |
||
30 | ;;; 3b - 7a = 1 を満たす a/b である |
||
31 | ;;; b <= 10^6 を満たす中で最大の b を求め |
||
32 | ;;; その時の a/b が答えになる |
||
33 | (define (a-b) |
||
34 | (let loop ([b #e1e6]) |
||
35 | ; 7a = 3b - 1 |
||
36 | (let ([current (- (* b 3) 1)]) |
||
37 | (if (zero? (mod current 7)) |
||
38 | `(,(div current 7) ,b) |
||
39 | (loop (- b 1)))))) |
||
40 | |||
41 | (define answer-71 (car (a-b))) |
||
42 | |||
43 | (format #t "71: ~d~%" answer-71) |
||
44 | 1 | Noppi | ``` |