結果
| 問題 | No.3663 LCM Decomposition |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-30 15:14:39 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 862 ms / 1,000 ms |
| + 84µs | |
| コード長 | 2,213 bytes |
| 記録 | |
| コンパイル時間 | 1,575 ms |
| コンパイル使用メモリ | 236,656 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-30 15:14:48 |
| 合計ジャッジ時間 | 6,561 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int Need = 1001001;
vector<bool> prime(Need+1,true);
prime.at(0) = false; prime.at(1) = false;
for(int i=2; i*i<=Need; i++){
if(!prime.at(i)) continue;
for(int k=i*i; k<=Need; k+=i) prime.at(k) = false;
}
int T; cin >> T;
while(T--){
long long N,L,R; cin >> N >> L >> R;
auto left = N;
vector<pair<long long,long long>> P;
vector<long long> D,D2;
for(int i=1; i*i<=N; i++) if(N%i == 0){
int now = 1;
while(i > 1 && left%i == 0) left /= i,now *= i;
if(now > 1) P.push_back({i,now});
D.push_back(i);
if(i*i != N) D.push_back(N/i);
}
if(left != 1) P.push_back({left,left});
sort(D.begin(),D.end());
int n = D.size();
for(auto d : D) if(L <= d && d <= R) D2.push_back(d);
vector<int> big(n,-1);
for(int i=0; i<n; i++) for(int k=D2.size(); k--;){
if(D2.at(k) < D.at(i)) break;
if(D2.at(k)%D.at(i) == 0){big.at(i) = D2.at(k); break;}
}
set<long long> S,S2;
auto del = [&](auto del,long long x) -> void {
if(S2.count(x)) return;
S2.insert(x);
if(S.count(x)) S.erase(x);
for(auto [p,ign] : P) if(x%p == 0) del(del,x/p);
};
bool ok = false;
for(int i=0; i<D2.size(); i++){
auto b = D2.at(i);
for(auto a : S){
auto ab = a*b/gcd(a,b);
long long c = 1;
for(auto [p,v] : P){
if(ab%v == 0) continue;
c *= v;
}
int pos = lower_bound(D.begin(),D.end(),c)-D.begin();
if(b < big.at(pos)){
c = big.at(pos);
cout << a << " " << b << " " << c << "\n",ok = true;
}
if(ok) break;
}
if(ok) break;
S.insert(b);
for(auto [p,ign] : P) if(b%p == 0) del(del,b/p);
}
if(!ok) cout << -1 << "\n";
}
}