結果

問題 No.1498 Factorization from -1 to 1
ユーザー t33ft33f
提出日時 2021-05-08 14:46:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 3,000 ms
コード長 1,008 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 83,740 KB
実行使用メモリ 11,448 KB
最終ジャッジ日時 2023-10-15 01:48:58
合計ジャッジ時間 4,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
10,960 KB
testcase_01 AC 38 ms
11,140 KB
testcase_02 AC 39 ms
10,996 KB
testcase_03 AC 203 ms
11,120 KB
testcase_04 AC 226 ms
10,956 KB
testcase_05 AC 233 ms
11,000 KB
testcase_06 AC 239 ms
10,960 KB
testcase_07 AC 231 ms
10,964 KB
testcase_08 AC 231 ms
11,448 KB
testcase_09 AC 233 ms
11,036 KB
testcase_10 AC 44 ms
11,100 KB
testcase_11 AC 43 ms
11,116 KB
testcase_12 AC 43 ms
10,992 KB
testcase_13 AC 42 ms
11,080 KB
testcase_14 AC 42 ms
10,956 KB
testcase_15 AC 38 ms
11,100 KB
testcase_16 AC 39 ms
10,988 KB
testcase_17 AC 38 ms
11,108 KB
testcase_18 AC 37 ms
11,156 KB
testcase_19 AC 38 ms
10,956 KB
testcase_20 AC 38 ms
11,076 KB
testcase_21 AC 37 ms
10,992 KB
testcase_22 AC 37 ms
11,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    vector<vector<long long> > factors(100100);
    vector<long long> rem(100100);
    for (int i = 1; i < rem.size(); i++)
        rem[i] = (long long)i * i + 1;
    for (int i = 1; i < factors.size(); i++) {
        long long p = rem[i];
        if (p == 1) continue;
        for (long long j = i; j < 100100; j += p)
            while (rem[j] % p == 0) {
                rem[j] /= p;
                factors[j].push_back(p);
            }
        for (long long j = p - i; j < 100100; j += p)
            while (rem[j] % p == 0) {
                rem[j] /= p;
                factors[j].push_back(p);
            }
    }

    for (auto& v : factors) sort(v.begin(), v.end());

    int q; cin >> q;
    while (q--) {
        int k; cin >> k;
        for (int i = 0; i < factors[k].size(); i++) {
            cout << factors[k][i] << (i == factors[k].size() - 1 ? '\n' : ' ');
        }
    }
}
0