Advertisement
spytheman123

Primes V

Oct 16th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 0.43 KB | Software | 0 0
  1. import time
  2.  
  3. fn main() {
  4.     max_n := arguments()[1] or { '100_000' }.int()
  5.     t := time.now()
  6.     mut primes := []int{cap: max_n}
  7.     primes << 2
  8.     mut check := 3
  9.     mut index := 1
  10.     for index < max_n {
  11.         mut is_prime := true
  12.         for prime in primes {
  13.             if (check % prime) == 0 {
  14.                 is_prime = false
  15.                 break
  16.             }
  17.         }
  18.         if is_prime {
  19.             primes << check
  20.             index += 1
  21.         }
  22.         check += 2
  23.     }
  24.     println(primes.len)
  25.     println(time.since(t))
  26. }
Tags: primes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement