當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Sieve.NextPrime方法代碼示例

本文整理匯總了Golang中euler.Sieve.NextPrime方法的典型用法代碼示例。如果您正苦於以下問題:Golang Sieve.NextPrime方法的具體用法?Golang Sieve.NextPrime怎麽用?Golang Sieve.NextPrime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在euler.Sieve的用法示例。


在下文中一共展示了Sieve.NextPrime方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: Run

func Run() {
	var s euler.Sieve

	count := 0
	sum := 0
	p := 11
	for count < 11 {
		if isRightPrime(&s, p) && isLeftPrime(&s, p) {
			sum += p
			count++
			// fmt.Printf("%d\n", p)
		}

		p = s.NextPrime(p)
	}
	fmt.Printf("%d\n", sum)
}
開發者ID:d3zd3z,項目名稱:euler,代碼行數:17,代碼來源:pr037.go

示例8: Run

func Run() {
	var sieve euler.Sieve

	num := start
	var prime int = 2
	for {
		if num == int64(prime) {
			fmt.Printf("%d\n", prime)
			break
		}

		// Divide out the prime as many times as possible.
		for num%int64(prime) == 0 {
			num /= int64(prime)
		}

		prime = sieve.NextPrime(prime)
	}
}
開發者ID:d3zd3z,項目名稱:euler,代碼行數:19,代碼來源:pr003.go

示例9: divisorCount

func divisorCount(sieve *euler.Sieve, n int) (result int) {
	result = 1
	tmp := n
	prime := 2

	for tmp > 1 {
		dcount := 0
		for tmp%prime == 0 {
			tmp /= prime
			dcount += 1
		}

		result *= dcount + 1

		if tmp > 1 {
			prime = sieve.NextPrime(prime)
		}
	}

	return
}
開發者ID:d3zd3z,項目名稱:euler,代碼行數:21,代碼來源:pr012.go


注:本文中的euler.Sieve.NextPrime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。