Last active
July 10, 2018 00:39
-
-
Save fetburner/ebfbd8412d02705f050186182e12a176 to your computer and use it in GitHub Desktop.
整数上の平方根
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec floor_sqrt acc acc_x_2_x_r sq_acc_minus_z r sq_r = | |
| if r = 0 then acc | |
| else | |
| let sq_acc_minus_z' = sq_acc_minus_z + acc_x_2_x_r + sq_r in | |
| ( if sq_acc_minus_z' <= 0 then | |
| floor_sqrt (acc + r) ((acc_x_2_x_r lsr 1) + sq_r) sq_acc_minus_z' | |
| else | |
| floor_sqrt acc (acc_x_2_x_r lsr 1) sq_acc_minus_z ) (r lsr 1) (sq_r lsr 2) | |
| let floor_sqrt z = floor_sqrt 0 0 (~-z) (1 lsl 30) (1 lsl 60) | |
| let true = | |
| List.for_all (fun i -> | |
| let n = floor_sqrt i in | |
| n * n <= i && i < (n + 1) * (n + 1)) @@ | |
| Array.to_list @@ Array.init 1000000 @@ fun i -> i | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment