SHARE
TWEET

Untitled

a guest Jul 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "math"
  6. )
  7.  
  8. const NUM = 100000
  9.  
  10. func main() {
  11.   prime := make([]int, NUM+1)
  12.   var i,j,limit int
  13.  
  14.   for i = 2; i < NUM-1; i++ {
  15.     prime[i] = 1
  16.   }
  17.   limit = int(math.Sqrt(float64(NUM)))
  18.   for i=2; i <= limit; i++ {
  19.     if prime[i] == 1 {
  20.       for j=2*i; j <=NUM; j++ {
  21.         if j % i == 0 {
  22.           prime[j] = 0
  23.         }
  24.       }
  25.     }
  26.   }
  27.   for i=2; i <=NUM; i++ {
  28.     if prime[i] == 1 {
  29.       fmt.Print("\n")
  30.       fmt.Print(i)
  31.     }
  32.   }
  33.   fmt.Print("\n")
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top