LoginSignup
10
9

More than 5 years have passed since last update.

シェルのワンライナーで素数を求める

Last updated at Posted at 2014-07-26

シェルのワンライナーで素数を求める

  • factorコマンド使えば簡単にできるのに気付いた
$ for i in {1..100} ; do test "${i}" = "$(factor $i | sed 's/[0-9]*: *//' | sed '/^$/d')" && echo $i ; done
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
10
9
1

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
10
9