結果

問題 No.2929 Miracle Branch
ユーザー t98slider
提出日時 2024-10-12 16:02:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 198,452 KB
最終ジャッジ日時 2025-02-24 18:21:04
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    if(x == 1){
        cout << 2 << '\n';
        cout << "1 2" << '\n'; 
        cout << "b g" << '\n';
        return 0;
    }
    vector<ll> b;
    for(int i = 2; i <= 200000; i++){
        if(x % i == 0){
            int cnt = 1;
            x /= i;
            while(x % i == 0){
                x /= i;
                cnt++;
            }
            if(i == 2){
                while(cnt >= 2){
                    b.emplace_back(4);
                    cnt -= 2;
                }
                if(cnt & 1) b.emplace_back(2);
            }else{
                while(cnt--) b.emplace_back(i);
            }
        }
    }
    if(x != 1 || b.size() + accumulate(b.begin(), b.end(), 0ll) > 200000){
        cout << -1 << '\n';
        return 0;
    }
    int n = b.size() + accumulate(b.begin(), b.end(), 0ll), cur = b.size();
    cout << n << '\n';
    for(int i = 1; i + 1 <= b.size(); i++){
        cout << i << ' ' << i + 1 << '\n';
    }
    for(int i = 0; i < b.size(); i++){
        for(int j = 0; j < b[i]; j++){
            cout << i + 1 << ' ' << ++cur << '\n';
        }
    }
    for(int i = 0; i < b.size(); i++){
        cout << 'b' << ' ';
    }
    for(int i = b.size(); i < n; i++){
        cout << 'g' << (i + 1 == n ? '\n' : ' ');
    }
}
0