Problem:
Least Common Multiple
Find the least common multiple (LCM) of given
n
integers.
Input
n
a
1
a
2
...
a
n
n
is given in the first line. Then,
n
integers are given in the second line.
Output
Print the least common multiple of the given integers in a line.
Constraints
2 ≤
n
≤ 10
1 ≤
a
i
≤ 1000
Product of given integers
a
i
(
i = 1, 2, ... n
) does not exceed 2
31
-1
Sample Input 1
3
3 4 6
Sample Output 1
12
Sample Input 2
4
1 2 3 5
Sample Output 2
30

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    
    vector<int> nums(n);
    cin >> nums[0];
    for (int i = 1; i < n; i++) {
        cin >> nums[i];
        int a = nums[i];
        int b = nums[i - 1];
        int f = a * b;
        
        while (1) {
            if (a > b) a = a - b;
            if (a < b) b = b - a;
            if (a == b) break;
        }
        f /= a;
        nums[i] = f;
    } 
    cout << nums.back() << endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3132
final_rank: 7

code_snippet: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a,b;
	cin>>n;
	cin>>b;
	for(int i=0;i<n-1;i++){
		cin>>a;
		int ans=a*b;
		while(true){
			if(a>b)
				a-=b;
			if(a<b)
				b-=a;
			if(a==b)
				break;
		}
		ans/=a;
		b=ans;
	}
	cout<<b<<endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3136
final_rank: 4

code_snippet: #include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> nums(n);
    cin >> nums[0];
    
    for (int i = 1; i < n; i++) {
        cin >> nums[i];
        int a = nums[i];
        int b = nums[i - 1];
        int f = a * b;
        
        while (1) {
            if (a > b) a = a - b;
            if (a < b) b = b - a;
            if (a == b) break;
        }
        
        f /= a;
        nums[i] = f;
    }
    
    cout << nums.back() << endl;
    
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3136
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> num(n);
    cin >> num[0];
    for (int i = 1; i < n; i++) {
        cin >> num[i];
        int a = num[i];
        int b = num[i - 1];
        int fin = a * b;
        while (1) {
            if (a > b) a = a - b;
            if (a < b) b = b - a;
            if (a == b) break;
        }
        fin /= a;
        num[i] = fin;
    }
    cout << num.back() << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 3136
final_rank: 8

code_snippet: #include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
}
int result=a[0];
for(int i=1;i<n;i++){
    int x=result,y=a[i];
    while(x!=y){
        if(x>y){
            x-=y;
        }else{
            y-=x;
        }
    }
        result=(a[i]*result)/x;
}
printf("%d\n",result);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2768
final_rank: 1

code_snippet: #include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);

    int integers[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &integers[i]);
    }

    int result = integers[0];
    for (int i = 1; i < n; i++) {
        int a = result, b = integers[i];
        while (a != b) (a > b) ? (a -= b) : (b -= a);
        result = (integers[i] * result) / a;
    }

    printf("%d\n", result);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2768
final_rank: 1

code_snippet: #include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);

    int integers[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &integers[i]);
    }

    int result = integers[0];
    for (int i = 1; i < n; i++) {
        int a = result;
        int b = integers[i];

        // Calculate GCD without using a user-defined function
        while (a != b) {
            if (a > b) {
                a -= b;
            } else {
                b -= a;
            }
        }

        // Calculate LCM using GCD
        result = (integers[i] * result) / a;
    }

    printf("%d\n", result);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2768
final_rank: 1

code_snippet: #include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int i,j,k,n;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++){
        cin>>ara[i];
    }
    sort(ara,ara+n);
    k=*max_element(ara,ara+n);
    for(j=k;;j+=k){
        int p=0;
        for(i=0;i<n;i++){
            if(j%ara[i]==0){
                p=1;
            }
            else{
                p=0;
                break;
            }
        }
        if(p==1){
            cout<<j<<endl;
            break;
        }
    }
}
accuracy: 1
time_ms: 60
memory_kb: 3180
final_rank: 5

code_snippet: #include <iostream>

using namespace std;

const int N = 10;

int main(){
    int n, num;
    int max = 0;
    int List_num[N];

    scanf("%d", &n);

    /*配列の初期化*/
    for (int i = 0; i < N; i++){
        List_num[i] = 0;
    }

    /*配列の要素入力*/
    for (int i = 0; i < n; i++){
        scanf("%d", &num);
        List_num[i] = (num);
        if (max < num){
            max = num;
        }
    }

    /*LCM導出*/
    int count = 1;
    int flag = 0;
    while(true){
        for (int i = 0; i < n; i++){
            if ((max*count) % List_num[i] != 0){
                //cout << max*count << " : " << List_num[i] << endl;
                count += 1;
                break;
            }
            else if(i == n-1){
                cout << max * count << endl;
                flag = 1;
            }
        }
        if (flag == 1) break;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3496
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std ;
#define MAX 1e9
#define NIL -2000000002
#define INF 2000000002
#define MAXN 123456
typedef long long int ll;
const int debug = 0 ; 
const int debug1 = 0 ; 
#define REP(i,n) for(int i=0; i<(int)n; i++)

int gcd (int u , int v){
    if ( u<v) swap(u,v);
    if (v==0 ) {return u;}
    while ( u-v >=0) {
        u -= v ;
    } 
    return gcd(v,u);
}

int lcm(int u,int v){
    int g = gcd(u,v);
    return g*(u/g)*(v/g); 
}

int main() {
    int n;
    vector<int> v;
    int a;
    int res=0;
    scanf ("%d", &n);
    REP(i,n) {
        scanf ("%d", &a);
        v.push_back(a);
    }
    while (v.size()>=2) {
        int u = v.size();
        res = lcm(v.at(u-1),v.at(u-2));     
        v.pop_back();
        v.pop_back();
        v.push_back(res);
    }
    printf ("%d\n",res);
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3564
final_rank: 10