main.go 1.3 KB

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