Advertisement
korobushk

greatestCDivR

Apr 19th, 2021
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.39 KB | None | 0 0
  1. public class app {
  2.     public static void main(String[] args) {
  3.         var result = gcd(8, 4);
  4.         System.out.println(result);
  5.     }
  6.  
  7.     public static int gcd(int a, int b) {
  8.         if (b == 0) {
  9.             return a;
  10.         }
  11.         if (a < 0 || b < 0) {
  12.             return -1;
  13.         }
  14.         return gcd(b, a % b);
  15.     }
  16. }
  17. //  euclidian  gdc(a,b) = gdc (b, a mod b)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement