Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tezamodel;
- import java.util.Scanner;
- public class TezaModel {
- public static int cmmdc(int a, int b) {
- if (a == b) {
- return a;
- }
- else if (a>b) {
- return cmmdc(a - b, b);
- } else {
- return cmmdc(a, b - a);
- }
- }
- public static int cmmmc(int a, int b) {
- return(a * b / cmmdc(a,b));
- }
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- int n = reader.nextInt();
- int a, b, x, y;
- a = reader.nextInt();
- b = reader.nextInt();
- x = a;
- y = b;
- b = cmmdc(a, b);
- y = cmmmc(x, y);
- for (int i = 0; i < n - 2; i++) {
- a = reader.nextInt();
- x = a;
- b = cmmdc(a, b);
- y = cmmmc(x, y);
- }
- System.out.println("Cmmdc: ");
- System.out.println(b);
- System.out.println("Cmmmc: ");
- System.out.println(y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement