Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

Q7

Recommended Posts

已知:前6个素数是2, 3, 5, 7, 11, 13, 我们说第6个素数是13;
那么:第10001个素数是多少呢?

package main

import (
	"fmt"
	"math/big"
)

func isPrimeNumber(intV int64) bool {

	return big.NewInt(intV).ProbablyPrime(0)

}

func GetPrimeNumberByIndex(indexV int64) int64 {

	var i int64 = 1
	var indexTemp int64 = 1

	for {
		i++
		if isPrimeNumber(int64(i)) {
			indexTemp++

			if indexTemp > indexV {

				break
			}

		}

	}

	return i

}
func main() {

	var indexV int64 = 10001
	var v int64 = GetPrimeNumberByIndex(indexV)
	fmt.Println("GetPrimeNumberByIndex(indexV)")
	fmt.Println(v)

}

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×