結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー GOTKAKO
提出日時 2026-08-30 14:21:26
言語 C++17
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,399 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,368 ms
コンパイル使用メモリ 226,224 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 14:22:35
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int T; cin >> T;
    while(T--){
        long long N,L,R; cin >> N >> L >> R;
        vector<long long> D,D2;
        for(int i=1; i*i<=N; i++) if(N%i == 0){
            D.push_back(i);
            if(i*i != N) D.push_back(N/i);
        }
        sort(D.begin(),D.end());
        int n = D.size();
        for(auto d : D) if(L <= d && d <= R) D2.push_back(d);

        vector<vector<tuple<long long,long long,long long>>> dp(3,vector<tuple<long long,long long,long long>>(n,{-1,-1,-1}));
        auto Pos = [&](int x) -> int {
            int pos = lower_bound(D.begin(),D.end(),x)-D.begin();
            return pos;
        };
        for(auto d : D2){
            for(int i=1; i>=0; i--) for(int k=0; k<n; k++){
                auto [a,b,c] = dp.at(i).at(k);
                if(a == -1) continue;
                long long x = d*D.at(k)/gcd(d,D.at(k));
                if(N%x) continue;
                auto pos = Pos(x);
                if(i == 0) b = d;
                else c = d;
                dp.at(i+1).at(pos) = {a,b,c};
            } 
            dp.at(0).at(Pos(d)) = {d,-1,-1};
        }
        {
            auto [a,b,c] = dp.at(2).at(n-1);
            if(a == -1) cout << "-1\n";
            else cout << a << " " << b << " " << c << "\n";
        }
    }
}
0