@@ -0,0 +1,1786 @@
+package MathProblem;%0A%0Aimport java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class MaximumGCDandSum %7B%0A    %0A    static final int N = 1000001;%0A    %0A    static int countA%5B%5D = new int%5BN%5D;%0A    static int countB%5B%5D = new int%5BN%5D;%0A    static int lmulA%5B%5D = new int%5BN%5D;%0A    static int lmulB%5B%5D = new int%5BN%5D;%0A%0A    static int maximumGcdAndSum(int%5B%5D A, int%5B%5D B, int n) %7B%0A        // Complete this function%0A        Arrays.fill(countA, 0);%0A        Arrays.fill(countB, 0);%0A        Arrays.fill(lmulA, 0);%0A        Arrays.fill(lmulB, 0);%0A        int max =0;%0A        %0A        //calculate max multiple in array a%0A        %0A        for(int i = 1; i %3C= n; i++) %7B%0A            countA%5BA%5Bi-1%5D%5D++;%0A        %7D%0A        for(int i = 1; i %3C N; i++) %7B%0A            for (int j = i; j %3C= N; j += i)%7B%0A                if(countA%5Bj%5D != 0)%7B%0A                    lmulA%5Bi%5D = j;%0A                %7D%0A            %7D%0A        %7D%0A        for(int i = 1; i %3C= n; i++) %7B%0A            countB%5BB%5Bi-1%5D%5D++;%0A        %7D%0A        for(int i = 1; i %3C N; i++) %7B%0A            for (int j = i; j %3C= N; j += i)%7B%0A                if(countB%5Bj%5D != 0)%7B%0A                    lmulB%5Bi%5D = j;%0A                %7D%0A            %7D%0A        %7D%0A        %0A        for(int i =1; i%3C N; i++)%7B%0A            if(lmulA%5Bi%5D %3E0 && lmulB%5Bi%5D %3E0)%7B%0A                max = lmulA%5Bi%5D + lmulB%5Bi%5D;%0A            %7D%0A        %7D%0A        %0A        return max;%0A    %7D%0A    %0A%0A    public static void main(String%5B%5D args) %7B%0A    Scanner in = new Scanner(System.in);%0A    int n = in.nextInt();%0A    int%5B%5D A = new int%5Bn%5D;%0A    for(int A_i = 0; A_i %3C n; A_i++)%7B%0A        A%5BA_i%5D = in.nextInt();%0A    %7D%0A    int%5B%5D B = new int%5Bn%5D;%0A    for(int B_i = 0; B_i %3C n; B_i++)%7B%0A        B%5BB_i%5D = in.nextInt();%0A    %7D%0A    int res = maximumGcdAndSum(A, B, n);%0A    System.out.println(res);%0A    %7D%0A%7D%0A

add maximum GCD and sum solution