-
-
Save athos/f1f030538a9c5857f76fe6c4f78c51c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repeating-decimal) | |
| (defn repeating-decimal [n] | |
| (loop [rem 1 rems #{} divs [] i 0] | |
| (let [div (int (/ (* rem 10) n)) | |
| rem (mod (* rem 10) n)] | |
| (if (and (not= rem 0) (contains? rems rem)) | |
| [n divs] | |
| (when (not= rem 0) | |
| (recur rem (conj rems rem) (conj divs div) (inc i))))))) | |
| (comment | |
| (repeating-decimal 7) | |
| (repeating-decimal 11) | |
| (repeating-decimal 12) | |
| (repeating-decimal 97) | |
| ) | |
| (defn solve [n] | |
| (loop [i n, m 0, divs []] | |
| (let [l (count divs)] | |
| (if (> i l) | |
| (let [divs' (repeating-decimal i) | |
| l' (count divs')] | |
| (if (> l' l) | |
| (recur (dec i) i divs') | |
| (recur (dec i) m divs))) | |
| [m divs])))) | |
| ;; (solve 100000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1/nの循環節の長さはnを超えない0〜n-1のn通り10000以下の数nで1/nが10000以上の長さの循環節を持つことはない100000,99999,99998, ...,その時点の循環節の最大長の範囲の数だけを探索すればいい