-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJohnAndGCDList.java
More file actions
43 lines (33 loc) · 1000 Bytes
/
JohnAndGCDList.java
File metadata and controls
43 lines (33 loc) · 1000 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
43
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
static int gcd(int a,int b){
if(b==0)
return a;
return gcd(b,a%b);
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args){
int t = scanner.nextInt();
while(t-- > 0){
int n = scanner.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = scanner.nextInt();
int[] ans = new int[n+1];
for(int i=0;i<n;i++){
if(i == 0)
ans[i] = arr[i];
else{
int lcm = (arr[i-1] * arr[i])/(gcd(arr[i-1],arr[i]));
ans[i] = lcm;
}
System.out.print(ans[i]+" ");
}
System.out.println(arr[n-1]);
}
}
}