Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package tezamodel;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TezaModel {
  6.  
  7.     public static int cmmdc(int a, int b) {
  8.         if (a == b) {
  9.             return a;
  10.         }
  11.         else if (a>b) {
  12.             return cmmdc(a - b, b);
  13.         } else {
  14.             return cmmdc(a, b - a);
  15.         }
  16.     }
  17.    
  18.     public static int cmmmc(int a, int b) {
  19.         return(a * b / cmmdc(a,b));
  20.     }
  21.    
  22.     public static void main(String[] args) {
  23.         Scanner reader = new Scanner(System.in);
  24.         int n = reader.nextInt();
  25.         int a, b, x, y;
  26.         a = reader.nextInt();
  27.         b = reader.nextInt();
  28.         x = a;
  29.         y = b;
  30.         b = cmmdc(a, b);
  31.         y = cmmmc(x, y);
  32.         for (int i = 0; i < n - 2; i++) {
  33.             a = reader.nextInt();
  34.             x = a;
  35.             b = cmmdc(a, b);
  36.             y = cmmmc(x, y);
  37.         }
  38.         System.out.println("Cmmdc: ");
  39.         System.out.println(b);
  40.         System.out.println("Cmmmc: ");
  41.         System.out.println(y);
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement