Upgrade to Pro — share decks privately, control downloads, hide ads and more …

페리 수열(Farey sequence)

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

페리 수열(Farey sequence)

페리 수열(farey sequence) 특징을 알아보고 관련된 project euler 문제 71, 72, 73을 풀어본다.

풀이 소스 코드를 제거하고 올림. (project euler에서 풀이를 공유하는 건 권장하지 않기 때문)

Avatar for Jongbin Oh

Jongbin Oh

May 09, 2022
Tweet

More Decks by Jongbin Oh

Other Decks in Programming

Transcript

  1. 페리 수열 / farey sequence 𝐹𝑝𝑟𝑒𝑠𝑒𝑛𝑡𝑖𝑜𝑛 = 0 1 ,

    1 2 , … , 페리 farey , 수열 sequence , … , ohye ohyecloudy , cloudy .com , … , 0 + 1 1 + 2 ohyecloudy / ohyecloudy.com 2013-06-08
  2. 페리 수열 𝐹𝑛 은 0 ≤ ℎ ≤ 𝑘 ≤

    𝑛 , gcd ℎ, 𝑘 = 1을 만족하는 ℎ 𝑘 를 오름차순으로 나열한 수열
  3. 페리 수열 𝐹𝑛 은 0 ≤ ℎ ≤ 𝑘 ≤

    𝑛 , gcd ℎ, 𝑘 = 1을 만족하는 ℎ 𝑘 를 오름차순으로 나열한 수열 기약분수 irreducible fraction 진분수 proper fraction
  4. 𝐹1 = 0 1 , 1 1 𝐹2 = 0

    1 , 1 2 , 1 1 𝐹3 = 0 1 , 1 3 , 1 2 , 2 3 , 1 1 𝐹4 = 0 1 , 1 4 , 1 3 , 1 2 , 2 3 , 3 4 , 1 1 ⋯
  5. 𝐹𝑞 에서 𝑎 𝑏 < 𝑝 𝑞 < 𝑐 𝑑

    인 𝑝 𝑞 는 𝑎+𝑐 𝑏+𝑑 로 구할 수 있다 1
  6. 𝐹𝑞 에서 𝑎 𝑏 < 𝑝 𝑞 < 𝑐 𝑑

    인 𝑝 𝑞 는 𝑎+𝑐 𝑏+𝑑 로 구할 수 있다 1 알고 있는 항 member
  7. 𝐹𝑞 에서 𝑎 𝑏 < 𝑝 𝑞 < 𝑐 𝑑

    인 𝑝 𝑞 는 𝑎+𝑐 𝑏+𝑑 로 구할 수 있다 1 새롭게 추가되는 항 이상하게 더하고 있어.
  8. 1 3 + 1 2 = 2 5 • 패기

    넘치는 분수 더하기 • 바보 셈 freshman sum • mediant
  9. 𝐹1 = 0 1 , 1 1 𝐹2 = 0

    1 , 1 2 , 1 1 𝐹3 = 0 1 , 1 3 , 1 2 , 2 3 , 1 1 ⋯ 0 + 1 1 + 1 = 1 2 0 + 1 1 + 2 = 1 3 1 + 1 2 + 1 = 2 3
  10. 𝐹1 = 0 1 , 1 1 𝐹2 = 0

    1 , 1 2 , 1 1 𝐹3 = 0 1 , 1 3 , 1 2 , 2 3 , 1 1 𝐹4 = 0 1 , 1 4 , 1 3 , 1 2 , 2 3 , 3 4 , 1 1 ⋯
  11. 𝐹1 = 0 1 , 1 1 𝐹2 = 0

    1 , 1 2 , 1 1 𝐹3 = 0 1 , 1 3 , 1 2 , 2 3 , 1 1 𝐹4 = 0 1 , 1 4 , 1 3 , 1 2 , 2 3 , 3 4 , 1 1 ⋯
  12. 𝐹1 = 0 1 , 1 1 𝐹2 = 0

    1 , 1 2 , 1 1 𝐹3 = 0 1 , 1 3 , 1 2 , 2 3 , 1 1 𝐹4 = 0 1 , 1 4 , 1 3 , 1 2 , 2 3 , 3 4 , 1 1 ⋯
  13. 기본적인 특징들 • 𝑎 𝑏 < 𝑝 𝑞 < 𝑐

    𝑑 인 𝑝 𝑞 = 𝑎+𝑐 𝑏+𝑑 • 𝐹𝑛 은 𝐹𝑛−1 을 포함 • 𝑎+𝑐 𝑏+𝑑 는 𝐹𝑏+𝑑 에서 처음으로 나타남
  14. Consider the fraction, 𝑛 𝑑 , where 𝑛 and 𝑑

    are positive integers. If 𝑛 < 𝑑 and HCF 𝑛, 𝑑 = 1, it is called a reduced proper fraction. If we list the set of reduced proper fractions for 𝑑 ≤ 8 in ascending order of size, we get: 1 8 , 1 7 , 1 6 , 1 5 , 1 4 , 2 7 , 1 3 , 3 8 , 2 5 , 3 7 , 1 2 , 4 7 , 3 5 , 5 8 , 2 3 , 5 7 , 3 4 , 4 5 , 5 6 , 6 7 , 7 8 It can be seen that 2 5 is the fraction immediately to the left of 3 7 . By listing the set of reduced proper fractions for 𝑑 ≤ 1,000,000 in ascending order of size, find the numerator of the fraction immediately to the left of 3 7 . http://projecteuler.net/problem=71 Project Euler #71
  15. 𝐹8 = ⋯ , 2 5 , 3 7 ,

    ⋯ 𝐹12 = ⋯ , 2 5 , 5 12 , 3 7 , ⋯ 𝐹19 = ⋯ , 5 12 , 8 19 , 3 7 , ⋯ … 𝐹1,000,000 = ⋯ , 𝑥, 3 7 , ⋯ 계산 필요 없다
  16. (defn rhs-farey-pair [[a b c d]] (let [mediant-n (+ a

    c) mediant-d (+ b d)] [mediant-n mediant-d c d])) (rhs-farey-pair [2 5 3 7])  [5 12 3 7] 2 5 , 3 7 5 12 , 3 7
  17. Consider the fraction, 𝑛 𝑑 , where 𝑛 and 𝑑

    are positive integers. If 𝑛 < 𝑑 and HCF 𝑛, 𝑑 = 1, it is called a reduced proper fraction. If we list the set of reduced proper fractions for 𝑑 ≤ 8 in ascending order of size, we get: 1 8 , 1 7 , 1 6 , 1 5 , 1 4 , 2 7 , 1 3 , 3 8 , 2 5 , 3 7 , 1 2 , 4 7 , 3 5 , 5 8 , 2 3 , 5 7 , 3 4 , 4 5 , 5 6 , 6 7 , 7 8 It can be seen that there are 3 fractions between 1 3 and 1 2 . How many fractions lie between 1 3 and 1 2 in the sorted set of reduced proper fractions for 𝑑 ≤ 12,000? http://projecteuler.net/problem=73 Project Euler #73
  18. 𝐹12,000 = 0 1 , 1 12,000 , 𝑥, ⋯

    이 두 항은 알 수 있다. 항상 0 1 , 1 𝑛
  19. 𝑎 𝑏 < 𝑐 𝑑 < 𝑝 𝑞 즉, 이

    두 항으로 다음 항을 구하는 방법
  20. 𝑎 𝑏 < 𝑐 𝑑 = 𝑎 + 𝑞 𝑏

    + 𝑞 < 𝑝 𝑞 𝒌𝑐 𝒌𝑑 = 𝑎+𝑝 𝑏+𝑞 를 만족하는 𝒌가 존재 𝑐 𝑑 는 기약분수이기 때문
  21. 𝑝 𝑞 = 𝑘𝑐 − 𝑎 𝑘𝑑 − 𝑏 𝒌𝑐

    𝒌𝑑 = 𝑎 + 𝑝 𝑏 + 𝑞 𝑛
  22. max (𝑘) = 𝑛 + 𝑏 𝑑 𝑘𝑑 − 𝑏

    ≤ 𝑛 𝑘 ≤ 𝑛 + 𝑏 𝑑
  23. 𝐹4 = 0 1 , 1 4 , 1 3

    , 1 2 , 𝑥, … 𝑎 𝑏 = 1 3 , 𝑐 𝑑 = 1 2 , 𝑘 = 4+3 2 = 3 𝑝 𝑞 = 2 3
  24. (defn next-term [[a b c d n]] (let [k (int

    (/ (+ n b) d)) p (- (* k c) a) q (- (* k d) b)] [c d p q n])) (next-term [1 3 1 2 4]) [1 2 2 3 4] 1 3 , 1 2 1 2 , 2 3
  25. (defn farey-seq [n] (take-while #(<= % 1) (map (fn [[a

    b _ _ _]] (/ a b)) (iterate next-term [0 1 1 n n])))) 𝐹2 = 0 1 , 1 2 , 1 1 , 3 2 , 2 1 , ⋯ 진분수 가분수 improper fraction
  26. Consider the fraction, 𝑛 𝑑 , where 𝑛 and 𝑑

    are positive integers. If 𝑛 < 𝑑 and HCF 𝑛, 𝑑 = 1, it is called a reduced proper fraction. If we list the set of reduced proper fractions for 𝑑 ≤ 8 in ascending order of size, we get: 1 8 , 1 7 , 1 6 , 1 5 , 1 4 , 2 7 , 1 3 , 3 8 , 2 5 , 3 7 , 1 2 , 4 7 , 3 5 , 5 8 , 2 3 , 5 7 , 3 4 , 4 5 , 5 6 , 6 7 , 7 8 It can be seen that there are 21 elements in this set. How many elements would be contained in the set of reduced proper fractions for 𝑑 ≤ 1,000,000? http://projecteuler.net/problem=72 Project Euler #72
  27. 𝐹 𝑛 에서는 𝐹𝑛−1 에 없는 어떤 항이 추가되나? gcd

    𝑛, 𝑎 = 1을 만족하는 𝑎 𝑛 가 추가
  28. 𝐹𝑛 = 𝐹𝑛−1 + 𝜑(𝑛) Euler's totient function 1 ≤

    𝑘 ≤ 𝑛, gcd 𝑛, 𝑘 = 1을 만족하는 정수 𝑘 개수
  29. 𝜑 𝑛 = 𝑛 (1 − 1 𝑝 ) 𝑝|𝑛

    𝑛을 나머지 없이 나누는 소수 prime
  30. 𝜑 2 = 𝜑 21 = 2 1 − 1

    2 = 1 𝜑 3 = 𝜑 31 = 3 1 − 1 3 = 2 𝜑 4 = 𝜑 22 = 4 1 − 1 2 = 2 𝜑 36 = 𝜑 2232 = 36 1 − 1 2 1 − 1 3 = 12
  31. (defn euler-totient [n] (* n (apply * (map #(- 1

    (/ 1 %)) (filter #(zero? (mod n %)) (take-while #(<= % n) primes))))))
  32. • 페리 수열 𝐹𝑛 은 0 ≤ ℎ ≤ 𝑘

    ≤ 𝑛 , gcd ℎ, 𝑘 = 1 을 만족하는 ℎ 𝑘 를 오름차순으로 나열한 수열. • 바보 셈으로 다음 항을 구하는 재미있는 특징. • Project Euler 문제는 어떤 수열에 관련된 문제 인지 안 가르쳐 줘
  33. CC BY-NC-SA 3.0 Reference Farey sequence – wikipedia 페리 수열

    – wikipedia mediant – wikipedia 바보 셈에서 페리수열로 – 네이버캐스트 @ohyecloudy