Esempio n. 1
0
package main

import "fmt"
import "libs/sieve"

const max = 1000000

var s = sieve.MakeSieve(max)

func countDigits(n int) int {
	digits := 0
	for ; n > 0; n /= 10 {
		digits += 1
	}
	return digits
}

func rotate(n int, digits int) int {
	p := n % 10
	for ; digits > 1; digits-- {
		p *= 10
	}
	return p + (n / 10)
}

func checkCircularPrime(n int) bool {
	digits := countDigits(n)
	for d := digits; d > 0; d-- {
		n = rotate(n, digits)
		if !s.IsPrime(int64(n)) {
			return false
Esempio n. 2
0
package main

import "fmt"
import "libs/sieve"

var s *sieve.Sieve = sieve.MakeSieve(10000)

func consecutivePrimes(a, b int64) int {
	var i int64
	for i = 1; s.IsPrime(i*i + a*i + b); i++ {
	}
	return int(i)
}

func main() {
	maxA, maxB, maxCount := int64(0), int64(0), 0

	for b := int64(0); b < 1000; b++ {
		if s.IsPrime(b) {
			for a := int64(-999); a < 1000; a++ {
				count := consecutivePrimes(a, b)
				if count > maxCount {
					maxA, maxB, maxCount = a, b, count
				}
			}
		}

	}
	fmt.Println(maxA, maxB, maxCount, maxA*maxB)
	//fmt.Println(1,41,consecutivePrimes(1,41))
	//fmt.Println(-79,1601,consecutivePrimes(-79,1601))
Esempio n. 3
0
package main

import "fmt"
import "libs/sieve"

const n = 10000

var s = sieve.MakeSieve(n)

type FactorTableEntry struct{ factor, remainder int }
type FactorTable []FactorTableEntry

var tab = make(FactorTable, n)

func computePropDivisors(i int) map[int]bool {
	if i == 1 {
		return map[int]bool{1: true}
	} else {
		fact := tab[i].factor
		rem := tab[i].remainder
		rv := computePropDivisors(rem)
		additions := make([]int, len(rv))
		j := 0
		for f, _ := range rv {
			additions[j] = f * fact
			j++
		}
		for _, f := range additions {
			rv[f] = true
		}
		return rv