Kuro-orzz's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:heavy_check_mark: NumberTheory/Math/test/aizu_ntl_1_c_lcm.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C"

#include "../../../template.h"

// lcm support C++17 and above only
// if C++ lower than 17, use x / __gcd(x, y) * y

void solve() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = a[0];
    for (int i = 1; i < n; i++) {
        ans = lcm(ans, a[i]);
    }
    cout << ans << '\n';
}
#line 1 "NumberTheory/Math/test/aizu_ntl_1_c_lcm.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C"

#line 2 "template.h"

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define MOD (ll)(1e9+7)
#define all(x) (x).begin(),(x).end()
#define unique(x) x.erase(unique(all(x)), x.end())
#define INF32 ((1ull<<31)-1)
#define INF64 ((1ull<<63)-1)
#define inf (ll)1e18

#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

const int mod = 998244353;

void solve();

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // cin.exceptions(cin.failbit);
    // int t; cin >> t;
    // while(t--)
        solve();
    cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << '\n';
    return 0;
}
#line 4 "NumberTheory/Math/test/aizu_ntl_1_c_lcm.test.cpp"

// lcm support C++17 and above only
// if C++ lower than 17, use x / __gcd(x, y) * y

void solve() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = a[0];
    for (int i = 1; i < n; i++) {
        ans = lcm(ans, a[i]);
    }
    cout << ans << '\n';
}
Back to top page