Finding prime numbers


At the same time as the first emperor, eradose, the first person to measure the circumference of the earth, developed the eradose sieve method


In the given sequence (2-N) table, all the multiples (not 0, 1, itself) of each element are erased, and all the prime numbers less than n are left

Finding prime numbers

Eradose sieve method

Count the prime numbers within n

func countPrimes(n int) int {
   var cnt int
   mark := make([]bool, n)
   for i:=2;i<n;i++{
       if !mark[i]{
           for j:=i+i;j<n;j+=i{
               mark[j] = true
   return cnt


The sum of four squares is just like this

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]