結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー t98slider
提出日時 2026-08-30 16:00:15
言語 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  
実行時間 814 ms / 1,000 ms
+ 978µs
コード長 2,241 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,218 ms
コンパイル使用メモリ 345,812 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 16:00:24
合計ジャッジ時間 7,117 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

unsigned long long xor64() {
    static unsigned long long x
        = (unsigned long long)(chrono::duration_cast<chrono::nanoseconds>(
            chrono::high_resolution_clock::now().time_since_epoch()).count())
            * 10150724397891781847ULL;
    x ^= x << 7;
    return x ^= x >> 9;
}

int int_rand(int r){
    return ((r * (xor64() & ((1 << 30) - 1))) >> 30);
}

tuple<ll,ll,ll> search(vector<ll> &divs, ll lcv){
    int n = divs.size();
    constexpr int th = 50;
    for(int i = 0; i < n && i < th; i++){
        for(int j = i + 1; j < n && j < th; j++){
            ll lv2 = lcm(divs.rbegin()[i], divs.rbegin()[j]);
            for(int k = j + 1; k < n && k < th; k++){
                if(lcm(lv2, divs.rbegin()[k]) == lcv){
                return make_tuple(divs.rbegin()[k], divs.rbegin()[j], divs.rbegin()[i]);
            }
            }
        }
    }
    for(int i = 0; i < 5000; i++){
        int c = max(2, int_rand(n));
        int b = max(1, int_rand(c));
        int a = int_rand(b);
        if(lcm(lcm(divs[a], divs[b]), divs[c]) == lcv){
            return make_tuple(divs[a], divs[b], divs[c]);
        }
    }
    int c = divs.size() - 1;
    for(int i = 0; i < 1000; i++){
        int b = max(1, int_rand(c));
        int a = int_rand(b);
        if(lcm(lcm(divs[a], divs[b]), divs[c]) == lcv){
            return make_tuple(divs[a], divs[b], divs[c]);
        }
    }
    return make_tuple(-1, -1, -1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        ll n, l, r;
        cin >> n >> l >> r;
        vector<ll> divs;
        for(ll i = 1; i * i <= n; i++){
            if(n % i == 0){
                if(l <= i && i <= r) divs.emplace_back(i);
                ll v = n / i;
                if(l <= v && v <= r && v != i) divs.emplace_back(v);
            }
        }
        if(divs.size() < 3){
            cout << "-1\n";
            continue;
        }
        sort(divs.begin(), divs.end());
        auto [A, B, C] = search(divs, n);
        if(A == -1){
            cout << "-1\n";
        }else{
            cout << A << ' ' << B << ' ' << C << '\n';
        }
    }
}
0