結果
| 問題 | No.3663 LCM Decomposition |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-08-30 15:21:41 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 76 ms / 1,000 ms |
| + 619µs | |
| コード長 | 3,034 bytes |
| 記録 | |
| コンパイル時間 | 2,746 ms |
| コンパイル使用メモリ | 363,372 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-30 15:21:47 |
| 合計ジャッジ時間 | 4,715 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
template<class T>
vector<T> divisors(T x) {
vector<T> res1, res2;
T d = 1;
for(; d * d < x; d++) {
if (x % d == 0) {
res1.emplace_back(d);
res2.emplace_back(x / d);
}
}
if (d * d == x) res1.emplace_back(d);
res1.insert(res1.end(), res2.rbegin(), res2.rend());
return res1;
}
template<class T>
vector<pair<T, int>> factorize(T x) {
vector<pair<T, int>> res;
for(T p = 2; p * p <= x; p++) {
int cnt = 0;
while(x % p == 0) x /= p, cnt++;
if (cnt) res.emplace_back(p, cnt);
}
if (x > 1) res.emplace_back(x, 1);
return res;
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, l, r;
cin >> n >> l >> r;
VI pes;
for (auto [p, e] : factorize(n)) {
int pe = 1;
rep(_, e) pe *= p;
pes.emplace_back(pe);
}
int sz = pes.size();
constexpr int INF = 1001001001;
vector<array<int, 3>> dp(1 << sz, array<int, 3>{INF, INF, INF});
VI divs = divisors(n);
int cand = 0;
for (int d : divs) if (l <= d && d <= r) {
cand++;
int s = 0;
rep(i, sz) if (d % pes[i] == 0) s |= 1 << i;
dp[s] = {d, -1, -1};
}
if (cand < 3) {
cout << -1 << '\n';
continue;
}
rrep(s, 1 << sz) if (dp[s][0] != INF) {
rep(i, sz) if (s >> i & 1) dp[s ^ (1 << i)] = dp[s];
}
rep(s, 1 << sz) {
for (int t1 = (s - 1) & s; t1; t1 = (t1 - 1) & s) {
int t2 = s ^ t1;
if (dp[t1][0] == INF || dp[t2][0] == INF) continue;
int c1 = find(all(dp[t1]), -1) - dp[t1].begin();
int c2 = find(all(dp[t2]), -1) - dp[t2].begin();
if (c1 + c2 > 3) continue;
if (dp[s][0] == INF || c1 + c2 < int(find(all(dp[s]), -1) - dp[s].begin())) {
dp[s] = {-1, -1, -1};
rep(i, c1) dp[s][i] = dp[t1][i];
rep(i, c2) dp[s][c1+i] = dp[t2][i];
}
}
}
auto ans = dp.back();
if (ans[0] == INF) {
cout << -1 << '\n';
} else {
for (int d : divs) if (l <= d && d <= r) {
rep(i, 3) {
if (ans[i] == d) break;
if (ans[i] == -1) {
ans[i] = d;
break;
}
}
}
sort(all(ans));
cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << '\n';
}
}
}
Kude