LoginSignup
1
1

More than 5 years have passed since last update.

Project Euler Q5 【最小の倍数】

Last updated at Posted at 2017-10-02

Project Eulerをワンライナーで解いてみる。
間違っていたらコメントください。

問題

2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である.

では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか.

解答

seq 2 20 |
factor |
awk '{print gsub(" 2"," 2",$0),gsub(" 3"," 3",$0),$0}' |
grep -e "^0 0" -e "^4 0" -e "^0 2" |
cut -d" " -f4-8 |
tr ' ' '\n' |
awk 'BEGIN{a=1}{a*=$1}END{print a}'
232792560

なげえ。
しかもなんかちょっとずるいので、なんとか直したい。
すごい久しぶりにcutを使った。

答え合わせ

こちらのサイト様と一致していればOKとした。
http://kingyojima.net/pje/005.html

1
1
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
1
1