結果

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

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Need = 1001001;
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i*i<=Need; i++){
        if(!prime.at(i)) continue;
        for(int k=i*i; k<=Need; k+=i) prime.at(k) = false;
    }
 
    int T; cin >> T;
    while(T--){
        long long N,L,R; cin >> N >> L >> R;
        auto left = N;
        vector<long long> P;
        vector<long long> D,D2;
        for(int i=1; i*i<=N; i++) if(N%i == 0){
            if(i > 1 && left%i == 0) P.push_back(i);
            while(i > 1 && left%i == 0) left /= i;
            D.push_back(i);
            if(i*i != N) D.push_back(N/i);
        }
        if(left != 1) P.push_back(left);
        sort(D.begin(),D.end());
        int n = D.size();
        for(auto d : D) if(L <= d && d <= R) D2.push_back(d);

        set<long long> S,S2;
        auto del = [&](auto del,long long x) -> void {
            if(S2.count(x)) return;
            S2.insert(x);
            if(S.count(x)) S.erase(x);
            for(auto p : P) if(x%p == 0) del(del,x/p);
        };
        bool ok = false;
        for(auto b : D2){
            for(auto a : S){
                auto c = N/(a*b/gcd(a,b));
                c = b/c*c+c;
                if(L <= c && c <= R){
                    cout << a << " " << b << " " << c << "\n";
                    ok = true; break;
                }
            }
            if(ok) break;
            S.insert(b);
            for(auto p : P) if(b%p == 0) del(del,b/p);
        }
        if(!ok) cout << -1 << "\n";
    }
}
0