PE-7 10001st prime

package main

import (
    "fmt"
    "math"
)

func main() {
    i := 2
    num := 1
    for num <= 10001 {
        if Prime(i) {
            num++
        }
        i++
    }
    fmt.Println(i - 1)
}
func Prime(num int) bool {
    if num == 2 || num == 3 {
        return true
    }
    if num%6 != 1 && num%6 != 5 {
        return false
    }
    tmp := int(math.Sqrt(float64(num)))
    for i := 5; i <= tmp; i += 6 {
        if num%i == 0 || num%(i+2) == 0 {
            return false
        }
    }
    return true
}

结果:104743

原文地址:https://www.cnblogs.com/miria-486/p/10093002.html

时间: 2024-10-10 23:57:16

PE-7 10001st prime的相关文章

10001st prime

problem 7:10001st prime 题意:求第10001个质数 代码如下: 1 #ifndef PRO7_H_INCLUDED 2 #define PRO7_H_INCLUDED 3 4 #include "prime.h" 5 6 namespace pro7{ 7 int solve(){ 8 int p[200005]; 9 getPrime(200000,p); 10 return p[10000]; 11 } 12 } 13 14 #endif // PRO7_H

PE 001~010

题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的偶数求和. 003(Largest prime factor):求600 851 475 143的最大质因数. 004(Largest palindrome product):求由两个三位数相乘得到的最大回文数. 005(Smallest multiple):求能被1~20中所有数整除的最小正整数.

欧拉计划(python) problem 7

10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? python code : import math sqrt=math.sqrt def func(x): k=int(sqrt(x))+1 for i in range(2,k)

Python练习题 035:Project Euler 007:第10001个素数

本题来自 Project Euler 第7题:https://projecteuler.net/problem=7 # Project Euler: Problem 7: 10001st prime # By listing the first six prime numbers: # 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. # What is the 10 001st prime number? # Answer

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

欧拉项目007:第10001个素数

10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? 使用埃拉托斯特尼筛法,不懂得自行Wiki 我的python代码: # -*- coding:utf-8 -*- #使用埃拉托斯尼特晒法 #从2开始 import math def

[2016-02-19][UVA][524][Prime Ring Problem]

UVA - 524 Prime Ring Problem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers  into each circle separately, and the

HDU 1010 Prime Ring Problem

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1. Input n (0 < n <

[HDU 1016]--Prime Ring Problem(回溯)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2