Created
January 12, 2023 04:40
-
-
Save vtamara/82d8336880b42b0a553a10d9ce791add to your computer and use it in GitHub Desktop.
Solution to first task of https://github.com/ton-blockchain/func-contest2
This file contains 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
{- | |
TASK 1 - Greatest Common Divisor | |
Write a method that calculates the greatest common divisor between 2 | |
integers greater than or equal to 1 and less than 1048576. | |
-} | |
() recv_internal() { | |
} | |
;; solution based on | |
;; https://people.cs.ksu.edu/~schmidt/301s14/Exercises/euclid_alg.html | |
(int) gcd(int a, int b) method_id { | |
int k = a; | |
int m = b; | |
if (b > a) { | |
k = b; | |
m = a; | |
} | |
;; k is max(a,b) and m = min(a,b) | |
while (m != 0) { | |
int r = k % m; | |
k = m; | |
m = r; | |
} | |
return k; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment