Submission #3912039


Source Code Expand

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return (a/g)*b;
}

ll solve(int N, ll Z, vll& a) {
    ll best = Z;

    ll l = 1;
    rep(i,N) {
        ll g = gcd(Z, a[i]);
        l = lcm(l, g);
    }
    return l;
}

int main() {
    int N; ll Z;
    scanf("%d%lld", &N, &Z);
    vll a(N);
    rep(i,N)
        scanf("%lld", &a[i]);
    cout << solve(N,Z,a) << endl;
    return 0;
}

Submission Info

Submission Time
Task B - GCDロボット
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2315 Byte
Status
Exec Time 68 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:69:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld", &N, &Z);
                            ^
./Main.cpp:72:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
                             ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_0, example_1, example_2
All 500 / 500 example_0, example_1, example_2, many_0, many_1, many_10, many_11, many_2, many_3, many_4, many_5, many_6, many_7, many_8, many_9, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_16, rand_17, rand_18, rand_19, rand_2, rand_20, rand_21, rand_22, rand_23, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9
Case Name Status Exec Time Memory
example_0 1 ms 256 KB
example_1 1 ms 256 KB
example_2 1 ms 256 KB
many_0 45 ms 1024 KB
many_1 22 ms 640 KB
many_10 42 ms 1024 KB
many_11 7 ms 384 KB
many_2 45 ms 1024 KB
many_3 2 ms 256 KB
many_4 45 ms 1024 KB
many_5 33 ms 768 KB
many_6 42 ms 1024 KB
many_7 34 ms 896 KB
many_8 42 ms 1024 KB
many_9 29 ms 768 KB
rand_0 67 ms 1024 KB
rand_1 32 ms 640 KB
rand_10 47 ms 1024 KB
rand_11 11 ms 384 KB
rand_12 68 ms 1024 KB
rand_13 53 ms 896 KB
rand_14 23 ms 1024 KB
rand_15 10 ms 640 KB
rand_16 68 ms 1024 KB
rand_17 15 ms 384 KB
rand_18 23 ms 1024 KB
rand_19 9 ms 512 KB
rand_2 21 ms 1024 KB
rand_20 21 ms 1024 KB
rand_21 16 ms 768 KB
rand_22 47 ms 1024 KB
rand_23 34 ms 768 KB
rand_3 3 ms 256 KB
rand_4 68 ms 1024 KB
rand_5 62 ms 1024 KB
rand_6 21 ms 1024 KB
rand_7 14 ms 768 KB
rand_8 21 ms 1024 KB
rand_9 4 ms 384 KB