結果

問題 No.368 LCM of K-products
ユーザー tatsukawatatsukawa
提出日時 2016-05-25 15:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,803 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 165,268 KB
実行使用メモリ 17,216 KB
最終ジャッジ日時 2024-04-16 16:36:22
合計ジャッジ時間 8,017 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll=int64_t;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define RER(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
template<typename T> void input(T &x, size_t n) { for(int i = 0; i < n; i++) { cin >> x[i]; } }
//=====debug======
void* enabler;
#define debug(...) cout << __VA_ARGS__ << endl;
template<typename T> class has_begin_and_end { private: template<typename U> static auto check( U v ) -> decltype( v.begin(), v.end(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; };
template<typename T> class has_top_and_pop { private: template<typename U> static auto check( U v ) -> decltype( v.empty(), v.top(), v.pop(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; }; template<typename T>
class has_front_and_pop { private: template<typename U> static auto check( U v ) -> decltype( v.empty(), v.front(), v.pop(), std::true_type() ); static auto check( ... ) -> decltype( std::false_type() ); public: typedef decltype( check( std::declval<T>() ) ) type; static bool const value = type::value; }; 
template<class T, typename std::enable_if<has_begin_and_end<T>::value>::type*& = enabler> void output(const T& val){ auto it = val.begin(); cout << (*it++); for(; it != val.end(); ++it) cout << ' ' << (*it); cout << endl; }
template<class T, typename std::enable_if<has_top_and_pop<T>::value>::type*& = enabler> void output(T val){ while(!val.empty()){ debug(val.top()); val.pop(); } }
template<class T, typename std::enable_if<has_front_and_pop<T>::value>::type*& = enabler> void output(T val){ while(!val.empty()){ debug(val.front()); val.pop(); } }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& v) { os << "(" <<  v.first <<  ", " << v.second << ")"; return os; } 

const int MOD = 1e9+7;

void extgcd(ll a, ll b, ll& x, ll& y) {
    if (b != 0) {
        extgcd(b, a%b, y, x);
        y -= a / b * x;
    }
    else {
        x = 1;
        y = 0;
    }
}

ll inv_mod(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

ll res = 1LL;
ll n, k;
ll a[1024];

void dfs(int index, int count, ll val) {
    if(index == n) {
        if(count == k) {
            res = (res * inv_mod(__gcd(res, val), MOD) * val) % MOD;
        } else {
            return;
        }
    }

    for(int i = index; i < n; i++) {
        dfs(index+1, count+1, val*a[i]);
        dfs(index+1, count, val);
    }
    return;
}

int main() {
    cin >> n >> k;
    vector<ll> b;
    input(a, n);
    dfs(0, 0, 1LL);
    cout << res << endl;
}
0