algorithm

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

View the Project on GitHub gtnao/algorithm

:heavy_check_mark: test/aoj/ntl_1_c.test.cpp

Depends on

Code

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

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

#include "../../src/math/lcm.hpp"

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    ans = lcm(ans, a);
  }
  cout << ans << endl;
  return 0;
}
#line 1 "test/aoj/ntl_1_c.test.cpp"
#define PROBLEM                                                                \
  "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C"

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

#line 2 "src/math/lcm.hpp"

#line 4 "src/math/lcm.hpp"
using namespace std;

#line 2 "src/math/gcd.hpp"

#line 4 "src/math/gcd.hpp"
using namespace std;

template <typename T = long long> T gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
#line 7 "src/math/lcm.hpp"

template <typename T = long long> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#line 8 "test/aoj/ntl_1_c.test.cpp"

int main() {
  int n;
  cin >> n;
  long long ans = 1;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    ans = lcm(ans, a);
  }
  cout << ans << endl;
  return 0;
}
Back to top page