当前位置: 首页>>代码示例>>Golang>>正文


Golang euler.Sieve类代码示例

本文整理汇总了Golang中euler.Sieve的典型用法代码示例。如果您正苦于以下问题:Golang Sieve类的具体用法?Golang Sieve怎么用?Golang Sieve使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Sieve类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func Run() {
	var s euler.Sieve

	p := 2
	count := 0

	// Move the closure out of the loop for efficiency.  It does
	// save some time.
	circular := true
	pcheck := func(num int) {
		if !s.IsPrime(num) {
			circular = false
		}
	}

	for p < 1000000 {
		circular = true
		eachRotation(p, pcheck)

		if circular {
			// fmt.Printf("%d\n", p)
			count++
		}
		p = s.NextPrime(p)
	}

	fmt.Printf("%d\n", count)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:28,代码来源:pr035.go

示例2: familySize

func familySize(sieve *euler.Sieve, base, part int) (size int) {
	orig := euler.DigitsOf(base)
	work := make([]int, len(orig))
	size = 0

	found := false
	for _, d := range orig {
		if d == part {
			found = true
			break
		}
	}
	if !found {
		return
	}

	for value := part; value <= 9; value++ {
		copy(work, orig)
		for i := range orig {
			if work[i] == part {
				work[i] = value
			}
		}

		prime := euler.OfDigits(work)
		if sieve.IsPrime(prime) {
			size++
		}
	}
	return
}
开发者ID:d3zd3z,项目名称:euler,代码行数:31,代码来源:pr051.go

示例3: Run

func Run() {
	var sieve euler.Sieve
	limit := 1000000
	ps := sieve.PrimesUpto(limit)

	longestLen := 0
	longestVal := 0

	for a := 1; a < len(ps); a++ {
		total := 0
		for b := a; b < len(ps); b++ {
			total += ps[b]
			if total >= limit {
				break
			}

			if b-a+1 > longestLen && sieve.IsPrime(total) {
				longestLen = b - a + 1
				longestVal = total
			}
		}
	}

	fmt.Printf("%d\n", longestVal)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:25,代码来源:pr050.go

示例4: Run

func Run() {
	var sieve euler.Sieve

	prime := 2
	for i := 0; i < 10000; i++ {
		prime = sieve.NextPrime(prime)
	}
	fmt.Printf("%d\n", prime)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:9,代码来源:pr007.go

示例5: isRightPrime

func isRightPrime(s *euler.Sieve, num int) bool {
	for num > 0 {
		if !s.IsPrime(num) {
			return false
		}
		num /= 10
	}
	return true
}
开发者ID:d3zd3z,项目名称:euler,代码行数:9,代码来源:pr037.go

示例6: longestSeries

func longestSeries(sieve *euler.Sieve, a, b int) int {
	for n := 0; ; n++ {
		c := n*n + a*n + b
		if c < 2 || !sieve.IsPrime(c) {
			return n
		}
	}
	panic("Not reached")
}
开发者ID:d3zd3z,项目名称:euler,代码行数:9,代码来源:pr027.go

示例7: init

func init() {
	earlyPrimes = make([]int, 10)
	var sieve euler.Sieve
	p := 2
	for i := range earlyPrimes {
		earlyPrimes[i] = p
		p = sieve.NextPrime(p)
	}
	return
}
开发者ID:d3zd3z,项目名称:euler,代码行数:10,代码来源:pr052.go

示例8: isAmicable

func isAmicable(s *euler.Sieve, a int) bool {
	if a >= limit {
		return false
	}
	b := s.ProperDivisorSum(a)
	if b >= limit || a == b {
		return false
	}
	c := s.ProperDivisorSum(b)
	return a == c
}
开发者ID:d3zd3z,项目名称:euler,代码行数:11,代码来源:pr021.go

示例9: Run

func Run() {
	var sv euler.Sieve

	largest := 0
	for p := 2; p < 9999999; p = sv.NextPrime(p) {
		if isPandigital(p) {
			largest = p
		}
	}

	fmt.Printf("%d\n", largest)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:12,代码来源:pr041.go

示例10: Run

func Run() {
	var sieve euler.Sieve

	all := make([][]euler.Factor, 0, 10000)
	for a := 2; a <= 100; a++ {
		for b := 2; b <= 100; b++ {
			tmp := factorPower(sieve.Factorize(a), b)
			all = append(all, tmp)
		}
	}
	sort.Sort(Nodes(all))
	all = unique(all)
	fmt.Printf("%v\n", len(all))
}
开发者ID:d3zd3z,项目名称:euler,代码行数:14,代码来源:pr029.go

示例11: goldbach

// Return the first goldbach prime for the given number, if present.
func goldbach(sieve *euler.Sieve, number int) (result int, present bool) {
	for _, p := range sieve.PrimesUpto(number) {
		if p == 2 {
			continue
		}
		_, perfect := perfect_root((number - p) / 2)
		if perfect {
			result = p
			present = true
			return
		}
	}
	return
}
开发者ID:d3zd3z,项目名称:euler,代码行数:15,代码来源:pr046.go

示例12: Run

func Run() {
	var s euler.Sieve

	n := 9
	for ; ; n += 2 {
		if s.IsPrime(n) {
			continue
		}
		_, present := goldbach(&s, n)
		if !present {
			break
		}
	}
	fmt.Printf("%d\n", n)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:15,代码来源:pr046.go

示例13: Run

func Run() {
	var sieve euler.Sieve
	largest := 0
	largestValue := 0

	for p := 7; p < 1000; p = sieve.NextPrime(p) {
		size := dlog(p)
		if size > largest {
			largest = size
			largestValue = p
		}
	}

	fmt.Printf("%d\n", largestValue)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:15,代码来源:pr026.go

示例14: Run

func Run() {
	var sieve euler.Sieve

	base := 2
	for {
		size := familySize(&sieve, base, 1)
		if size >= 8 {
			break
		}

		base = sieve.NextPrime(base)
	}

	fmt.Printf("%d\n", base)
}
开发者ID:d3zd3z,项目名称:euler,代码行数:15,代码来源:pr051.go

示例15: isLeftPrime

func isLeftPrime(s *euler.Sieve, num int) bool {
	mod := 1
	for mod < num {
		mod *= 10
	}

	for mod > 1 {
		num %= mod
		mod /= 10
		if !s.IsPrime(num) {
			return false
		}
	}

	return true
}
开发者ID:d3zd3z,项目名称:euler,代码行数:16,代码来源:pr037.go


注:本文中的euler.Sieve类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。