-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmaximize.java
More file actions
42 lines (35 loc) · 907 Bytes
/
Copy pathmmaximize.java
File metadata and controls
42 lines (35 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package RandomCF;
import java.util.Scanner;
public class mmaximize {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int testcases = input.nextInt();
for (int i = 0; i < testcases; i++) {
int number = input.nextInt();
System.out.println(highdiv(number));
}
}
static int highdiv(int num) {
int maxi = 1;
for (int j = 1; j <= num; j++) {
if (maxi > findGCD(num, j) + j) {
maxi = findGCD(num, j) + j;
}
}
if (maxi > num) {
return maxi;
} else {
return num - 1;
}
}
public static int findGCD(int a, int b) {
while (b != 0) {
if (a > b) {
a = a - b;
} else {
b = b - a;
}
}
return a;
}
}