結果

問題 No.3663 LCM Decomposition
コンテスト
ユーザー pia019
提出日時 2026-08-30 16:28:51
言語 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
結果
TLE  
実行時間 -
コード長 2,907 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,172 ms
コンパイル使用メモリ 384,196 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 16:29:00
合計ジャッジ時間 7,779 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const ll MOD = 998244353;
const double INFD = 1.0E10;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
//const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Pair = pair<ll, ll>;
using Graph = vector<vector<int>>;
using mint = atcoder::modint998244353;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    
    
    //素数を列挙
    int M = 1e5;
    vector<bool> is_prime(M, true);
    is_prime[0] = false;
    is_prime[1] = false;
    vector<ll> primes;
    for (int i = 2; i < M; i++){
        if (!is_prime[i]) continue;
        primes.push_back(i);
        for (int j = i; j < M; j += i) is_prime[j] = false;
    }
    
    int T; cin >> T;
    while (T--){
        ll n, l, r; cin >> n >> l >> r;
        
        //素因数分解
        ll x = n;
        vector<pair<ll, ll>> vec;
        for (auto p : primes){
            ll tmp = 0;
            while (x % p == 0){
                x /= p;
                tmp++;
            }
            // cerr << p << " : " << tmp << endl;
            if (tmp) vec.push_back({p, tmp});
        }
        
        if (x > 1) vec.push_back({x, 1});
        
        //[l,r]に3つ以上存在していて、どれかが互いに素であればよい。
        int m = vec.size();
        // cerr << m << endl;
        vector<ll> nums;
        x = 1;
        auto rec = [&](auto &&self, int idx = 0){
            // cerr << x << endl;
            if (idx == m){
                if (l <= x && x <= r) nums.push_back(x);
                return;
            }
            
            auto [p, q] = vec[idx];
            for (int i = 0; i <= q; i++){
                self(self, idx + 1);
                x *= p;
            }
            for (int i = 0; i <= q; i++) x /= p;
        };
        
        rec(rec);
        sort(nums.begin(), nums.end());
        // for (auto e : nums) cerr << e << endl;
        m = nums.size();
        
        bool flag = false;
        tuple<ll, ll, ll> ans;
        for (int i = 0; i < m; i++){
            for (int j = i + 1; j < m; j++){
                for (int k = j + 1; k < m; k++){
                    ll x = lcm(nums[i], nums[j]);
                    x = lcm(x, nums[k]);
                    if (x == n){
                        ans = {nums[i], nums[j], nums[k]};
                        flag = true;
                    }
                    if (flag) break;
                }
                if (flag) break;
            }
            if (flag) break;
        }
        
        if (flag){
            auto [a, b, c] = ans;
            cout << a << " " << b << " " << c << '\n';
        }
        else cout << -1 << '\n';
    }
    
    return 0;
}
0