Problem: Given are N positive integers A_1,...,A_N.  Consider positive integers B_1, ..., B_N that satisfy the following condition.  Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.  Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.  Since the answer can be enormous, print the sum modulo (10^9 +7).

Submission attempts (in order):
def gcd(a,b):
  if a==0:return b
  return gcd(b%a,a)
n = int(input())
a = list(map(int, input().split()))
#print(a)
b=[]
for i in range(n):
    #print(i)
    b.append(a[i])
for i in range(n):
    if i != 0:
        b[i]=int(b[i-1]/int(gcd(b[i-1],b[i])))*b[i]
lcm=b[n-1]
ans=0
for i in range(n):
    #print(a[i])
    ans=(ans+lcm/a[i])
print(int(ans%(10**9+7))


import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
    static int N = (int)1e9 + 7;
    public static void main(String[] args){
        MyReader mr = new MyReader();
        PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int n = mr.nextInt();
        int[] arr = mr.nextIntArray(n);

        BigInteger l = BigInteger.valueOf(arr[0]);

        for(int i = 1;i<n;i++){
            l = lcm(l,BigInteger.valueOf(arr[i]));
        }

        BigInteger sum = BigInteger.valueOf(0);
        for(int num : arr){
            BigInteger tmp = l.divide(BigInteger.valueOf(num));
            sum = sum.add(tmp);

        }



        System.out.println(sum.mod(BigInteger.valueOf(N)).toString());







    }

    static BigInteger lcm(BigInteger a, BigInteger b){
        BigInteger gcd = a.gcd(b);
        BigInteger mul = a.multiply(b);
        BigInteger res = mul.divide(gcd);
        return res;
    }



    static class MyReader {
        BufferedReader br;
        StringTokenizer st;

        MyReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String res = "";
            try {
                res = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return res;
        }

        int[] nextIntArray(int n){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch (Exception e){
                e.printStackTrace();
            }
            int[] arr = new int[n];
            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(st.nextToken());
            }

            return arr;
        }

        long[] nextLongArray(int n){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch (Exception e){
                e.printStackTrace();
            }
            long[] arr = new long[n];
            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(st.nextToken());
            }

            return arr;
        }

        String[] nextStringArray(int n){
            String res = "";
            try{
                res = br.readLine();
            }
            catch (Exception e){
                e.printStackTrace();
            }

            String[] arr = res.split(" ");
            return arr;
        }
    }

    static class Pair {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

}




n = int(input())
arr = list(map(int,input().split()))

N = pow(10,9)+7
def gcd(a,b):
    if a==0:return b
    return gcd(b%a,a)

def lcm(a,b):
    tmp =  (a*b)//gcd(a,b)
    return tmp

hcm = arr[0]
for i in range(1,n):
    hcm = lcm(hcm,arr[i])

res = 0
for num in arr:
    res += (hcm//num)
    

print(res%N)
    

    


Verdicts: Runtime Error

Runtime Error

Accepted