0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

約分せよ

0
Last updated at Posted at 2026-04-25

問題

\frac{148953}{298767} 

を約分せよ。

約分といえば

ユークリッドの互除法!(ドラ〇もんが道具を取り出す風に)

実装

ユークリッドの互除法のメインロジック。

(define (euclid-gcd a b)
  (if (= b 0)
      a
      (euclid-gcd b (remainder a b))))

これだけでは不親切なので、約分する手続きも実装します。新たに手続きを作ることは、外部から実装の細部を隠す役割もあります。

(define (yakubun n d)
  (let ((g (euclid-gcd n d)))
    (cons (/ n g) (/ d g))))

n に分子、d に分母を指定します。

実行

約分してみます。

gosh> (yakubun 148953 298767)
(173 . 347)

回答

\frac{148953}{298767} = \frac{173}{347} 

蛇足

なお、Gauche は有理数をサポートするので、普通に約分できます。

gosh> (/ 148953 298767)
173/347

プログラムいらんやないかーい。(爆)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?