結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー Unbakedbread
提出日時 2026-08-30 13:54:14
言語 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
結果
WA  
実行時間 -
コード長 1,603 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,407 ms
コンパイル使用メモリ 354,148 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 13:54:27
合計ジャッジ時間 5,712 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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;
    
    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();
    
    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(b < nd[i]) {
    		const int nbit = val | bit[i];
    		if(nbit == (1 << M) - 1) {
    			cout << a << " " << b << " " << nd[i] << "\n";
    			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