[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonpeixun/article/master/python/python_recursive_prime.md [Back]  [Original]

#N
18610508486@163.com

## 2pythongolang  

[python](https://github.com/pythonpeixun/article/blob/master/python_shiping.md)

[python](https://github.com/pythonpeixun/article/blob/master/index.md)


    #coding:utf-8
    import math
    """
    python
    https://github.com/pythonpeixun/article/blob/master/beijing_weekend.md
    python
    https://github.com/pythonpeixun/article/blob/master/index.md
    :qq:1465376564  python

    """
    def check_pr(a, b):
        """2 a  b=sqrt(a),a"""
        if b < 2 and a > 1:
            return True
        elif a % b == 0:
            return False
        else:
            return check_pr(a, b-1)

    def nth_prime(n):
        """n2"""
        count = 0
        def helper(i=1):
            nonlocal count
            if check_pr(i, int(math.sqrt(i))):
                count += 1
                if count == n:
                    return i
            return helper(i+1)

        return helper

    if __name__ == '__main__':
        n = 100
        print(nth_prime(n)())

##golang  

    package main

    import (
    	"fmt"
    	"math"
    )

    // 
    func isPrime(a int, b float64) bool {
    	if b < 2 && a > 1 {
    		return true
    	} else if a%int(b) == 0 {
    		return false
    	} else {
    		return isPrime(a, b-1)
    	}
    }

    // N
    func nPrime(n int) int {
    	count := 0
    	var helper func(i int) int
    	helper = func(i int) int {
    		if isPrime(i, math.Sqrt(float64(i))) {
    			count += 1
    			if count == n {
    				return i
    			}

    		}
    		return helper(i + 1)

    	}
    	return helper(1)
    }

    func main() {
    	n := 100
    	fmt.Println(nPrime(n))

    }

Web Proxy Viewer  |  New URL  |  Original Page