結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー Unbakedbread
提出日時 2026-08-30 14:03:39
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 748 ms / 1,000 ms
+ 206µs
コード長 1,918 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,177 ms
コンパイル使用メモリ 355,576 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 14:03:49
合計ジャッジ時間 6,777 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int solve(void) {
    int N, Li, Ri;
    cin >> N >> Li >> Ri;
    
    int nN = N;
    
    vector<int> d;
    for(int i = 1; i * i <= N; ++i) {
    	if(N % i) continue;
    	d.push_back(i);
    	if(N != i * i) d.push_back(N / i);
    }
    
    vector<int> nd;
    for(auto x : d) if(Li <= x and x <= Ri) nd.push_back(x);
    sort(nd.begin(), nd.end());
    const int L = nd.size();
    
    if(L < 3) {
    	cout << -1 << "\n";
    	return 0;
    }
    
    vector<int> T;
    for(int i = 2; i * i <= N; ++i) {
    	int cnt = 1;
    	while(N % i == 0) {
    		N /= i;
    		cnt *= i;
    	}
    	if(cnt != 1) T.push_back(cnt);
    }
    if(N != 1) T.push_back(N);
    const int M = T.size();
    
    vector<int> bit(L, 0);
    rep(i, L) rep(j, M) if(nd[i] % T[j] == 0) bit[i] |= (1 << j);
    
    map<int, int> mp1;
    rep(i, L) if(!mp1.count(bit[i])) mp1[bit[i]] = nd[i];
    
    map<int, pair<int, int>> mp2;
    for(auto [val, a] : mp1) rep(i, L) if(a != nd[i]) {
    	const int nbit = val | bit[i];
    	if(!mp2.count(nbit)) mp2[nbit] = {a, nd[i]};
    }
    
    for(auto [val, p] : mp2) {
    	auto [a, b] = p;
    	rep(i, L) if(a != nd[i] and b != nd[i]) {
    		const int nbit = val | bit[i];
    		if(nbit == (1 << M) - 1) {
    			vector<int> v = {a, b, nd[i]};
    			sort(v.begin(), v.end());
    			cout << v[0] << " " << v[1] << " " << v[2] << "\n";
    			
    			assert(Li <= v[0] and v[0] < v[1] and v[1] < v[2] and v[2] <= Ri);
    			assert(lcm(a, lcm(b, nd[i])) == nN);
    			
    			return 0;
    		}
    	}
    }
    
    cout << -1 << "\n";
    
    return 0;
}

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int Testcases = 1;
    cin >> Testcases;
    while(Testcases--) solve();
    
    return 0;
}

0