結果
問題 | No.368 LCM of K-products |
ユーザー | h_noson |
提出日時 | 2016-04-30 00:22:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,056 bytes |
コンパイル時間 | 592 ms |
コンパイル使用メモリ | 61,644 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-15 07:54:55 |
合計ジャッジ時間 | 1,679 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,948 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 1 ms
6,940 KB |
testcase_29 | AC | 1 ms
6,944 KB |
testcase_30 | WA | - |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
testcase_33 | WA | - |
testcase_34 | AC | 2 ms
6,940 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n-1,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 #define MOD 1000000007 typedef long long ll; ll gcd(int a, int b) { return b == 0 ? a : gcd(b,a%b); } ll power(ll x, int n) { ll ret = 1; while (n > 0) { if (n % 2) { ret *= x; ret %= MOD; } x *= x; x %= MOD; n /= 2; } return ret; } ll lcm(ll a, ll b) { return a * b % MOD * power(gcd(a,b),MOD-2) % MOD; } int main() { int i, n, k, d; ll ans; int a[1000]; cin >> n >> k; rep (i,n) cin >> a[i]; if (k == 1) { ans = 1; rep (i,n) ans = lcm(ans,a[i]); } else { ans = a[0]; REP (i,1,n) ans = (ans * a[i]) % MOD; d = 1; rep (i,n) d = gcd(d,a[i]); ans = (ans * power(d,MOD-2)) % MOD; } cout << ans << endl; return 0; }