Advertisement
zvoulgaris

Approximate Squaring drill

Jun 8th, 2021
1,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.32 KB | None | 0 0
  1. # Approximate squaring drill
  2.  
  3. function as(n::Int64, d::Int64)
  4.     c = 0
  5.     n = BigInt(n)
  6.     d = BigInt(d)
  7.  
  8.     while d > 1
  9.         c += 1
  10.         x = ceil(BigInt, n / d)
  11.         q, r = divrem(d, x)
  12.  
  13.         if r == 0
  14.             d = q
  15.         else
  16.             n *= x
  17.         end
  18.     end
  19.  
  20.     return n, c
  21. end
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement