daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest Jun 6th, 2018 53 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.     "time"
  7. )
  8.  
  9. var lista = make([]int, 10, 10)
  10. var idx = 0
  11.  
  12. func CheckPrime(numero int) {
  13.     var lim = (int)(math.Floor(math.Sqrt(float64(numero))) + 1)
  14.  
  15.     for j := 0; j < idx; j++ {
  16.         if numero%lista[j] == 0 {
  17.             return
  18.         }
  19.         if lista[j] > lim {
  20.             break
  21.         }
  22.     }
  23.     if idx == len(lista) {
  24.         lista = append(lista, make([]int, idx*2, idx*2)...)
  25.     }
  26.     lista[idx] = numero
  27.     idx++
  28. }
  29.  
  30. func GetPrimes(numerMax int) {
  31.     for i := 3; i < numerMax; i += 2 {
  32.         CheckPrime(i)
  33.     }
  34. }
  35.  
  36. func main() {
  37.     calculaTiempo(func() {
  38.         GetPrimes(67108864)
  39.     })
  40.     fmt.Println(idx, lista[idx])
  41. }
  42.  
  43. func calculaTiempo(funcion func()) {
  44.     lista[0] = 2
  45.     idx++
  46.     fmt.Println(time.Now())
  47.     funcion()
  48.     fmt.Println(time.Now())
  49. }
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