Exemplo n.º 1
0
func main() {
	i := 1
	n := big.NewInt(1)
	q := big.NewInt(0)
	p, err := cache.BaseExp(10, 99999999)
	if err != nil {
		panic(err)
	}
	l := p.BitLen()
	fmt.Printf("LEN: %10d\n", l)
	for q = range sieve.BigSieve() {
		n.Mul(n, q)
		if i < 1000000 {
			// Skip ahead. For small numbers, console output is the bottleneck.
			i++
			continue
		}
		c := n.BitLen()
		fmt.Printf("\rLEN: %10d %d", c, i)
		if c > l {
			// It looks like we've found our number!
			fmt.Println()
			break
		}
		i++
	}
}
Exemplo n.º 2
0
// Just like Split, but return an error when receiving a kill signal from t.
func splitOrQuit(z *big.Int, quit <-chan time.Time) (p, q *big.Int, err error) {
	q, r := big.NewInt(0), big.NewInt(0)
	if z.Sign() == 0 {
		return
	}
	max := roughSqrt(z)
	primes := sieve.BigSieve()
	for {
		select {
		case <-quit:
			err = ErrTimeout
			return
		case p = <-primes:
			if q.DivMod(z, p, r); r.Sign() == 0 {
				return
			}
			if max.Cmp(p) == -1 {
				q.SetInt64(1)
				p.Set(z)
				return
			}
		}
	}
	return
}
Exemplo n.º 3
0
// Modder creates a generator that yields remainders of z for each prime.
func Modder(z *big.Int) *modder {
	return &modder{
		z:     z,
		q:     big.NewInt(1),
		r:     big.NewInt(0),
		t:     big.NewInt(0),
		sieve: sieve.BigSieve(),
	}
}