結果

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

ソースコード

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){
    if(lcm(lcm(divs.rbegin()[2], divs.rbegin()[1]), divs.rbegin()[0]) == lcv){
        return make_tuple(divs.rbegin()[2], divs.rbegin()[1], divs.rbegin()[0]);
    }
    int n = divs.size();
    for(int i = 0; i < 1000; i++){
        int a = int_rand(n);
        int b = int_rand(n);
        while(b == a) b = int_rand(n);
        int c = int_rand(n);
        while(c == a || c == b) c = int_rand(n);
        if(lcm(lcm(divs[a], divs[b]), divs[c]) == lcv){
            if(a > b) swap(a, b);
            if(b > c) swap(b, c);
            if(a > b) swap(a, b);
            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