「素数」の版間の差分
imported>MikeCAT 作成 |
imported>MikeCAT 外部リンクを追加、その他微調整 |
||
| (他の1人の利用者による、間の1版が非表示) | |||
| 1行目: | 1行目: | ||
'''素数'''とは、1とその数でしか割り切れない2以上の[[整数]]であり、[[東工大生]]の大好物である。 | '''素数'''とは、1とその数でしか割り切れない2以上の[[整数]]であり、[[東工大生]]の大好物である。 | ||
落ち着くために数える人もいるとされる。 | |||
==素数判定== | ==素数判定== | ||
=== [[F Sharp|F#]]による記述例 === | |||
<source lang="fsharp"> | |||
let isPrime (number : bigint) = | |||
match number with | |||
| _ -> seq { bigint(2) .. bigint(sqrt(float number))} | |||
|> Seq.exists (fun x -> if (number % x = bigint(0)) then true else false) | |||
|> not | |||
let primes = | |||
Seq.initInfinite (fun i -> i + 2) //need to skip 0 and 1 for isPrime | |||
|> Seq.map (fun i -> bigint(i)) | |||
|> Seq.filter isPrime | |||
printfn "%A" primes;; | |||
</source> | |||
===愚直な方法=== | ===愚直な方法=== | ||
<source lang="c"> | <source lang="c"> | ||
| 207行目: | 226行目: | ||
} | } | ||
</source> | </source> | ||
== 外部リンク == | |||
* [http://www.amazon.co.jp/dp/4873101565 Amazon.co.jp: 素数表150000個: 真実のみを記述する会: 本] | |||
* [http://pn.ideeile.com/ 素数判定| Project IDEEILE] | |||
* [http://www.primegrid.com/ PrimeGrid] | |||
==関連項目== | ==関連項目== | ||
| 217行目: | 241行目: | ||
* [[合成数]] | * [[合成数]] | ||
* [[素因数分解]] | * [[素因数分解]] | ||
* [[対お姉ちゃん用決戦部隊、通称チマメ隊]] | |||