1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// Copyright (c) jnml. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
// Factor Finder - searches for Mersenne number factors of one specific special
// form.
package main
import (
"flag"
"fmt"
"math/big"
"runtime"
"time"
"github.com/cznic/mathutil"
)
const (
pp = 1
pp2 = 10
)
var (
_1 = big.NewInt(1)
_2 = big.NewInt(2)
)
func main() {
runtime.GOMAXPROCS(2)
oClass := flag.Uint64("c", 2, `factor "class" number`)
oDuration := flag.Duration("d", time.Second, "duration to spend on one class")
flag.Parse()
class := *oClass
for class&1 != 0 {
class >>= 1
}
class = mathutil.MaxUint64(class, 2)
for {
c := time.After(*oDuration)
factor := big.NewInt(0)
factor.SetUint64(class)
exp := big.NewInt(0)
oneClass:
for {
select {
case <-c:
break oneClass
default:
}
exp.Set(factor)
factor.Lsh(factor, 1)
factor.Add(factor, _1)
if !factor.ProbablyPrime(pp) {
continue
}
if !exp.ProbablyPrime(pp) {
continue
}
if mathutil.ModPowBigInt(_2, exp, factor).Cmp(_1) != 0 {
continue
}
if !factor.ProbablyPrime(pp2) {
continue
}
if !exp.ProbablyPrime(pp2) {
continue
}
fmt.Printf("%d: %s | M%s (%d bits)\n", class, factor, exp, factor.BitLen())
}
class += 2
}
}
|