zvoulgaris

Coprimes drill

Sep 4th, 2020
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.68 KB | None | 0 0
  1. # Co-prime drill
  2.  
  3. function gcd(x::Integer, y::Integer)
  4.     while (x > 0) && (y > 0)
  5.         if x < y
  6.             y = y % x
  7.         else
  8.             x = x % y
  9.         end
  10.     end
  11.  
  12.     return max(x, y)
  13. end
  14.  
  15. AreCoprime(x::Integer, y::Integer) = (gcd(x, y) == 1)
  16.  
  17. function main(n_max::Integer)
  18.     x = 9 # n = 0
  19.     y = 10 # n = 1
  20.    
  21.     for n = BigInt.(2:n_max)
  22.         n % 50000 == 0 && println(n)
  23.         x = y
  24.         y = n^17 + 9
  25.  
  26.         if !AreCoprime(x, y)
  27.             println("Rule breaks at n = ", n, " as ", x, " and ", y, " are not coprime!")
  28.             return
  29.         end    
  30.     end
  31.  
  32.     println("\nAll cases up to n = ", n_max, " were coprimes...")
  33. end
Add Comment
Please, Sign In to add comment