結果

問題 No.1498 Factorization from -1 to 1
ユーザー sgswsgsw
提出日時 2021-05-04 14:38:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 3,000 ms
コード長 1,071 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 207,988 KB
実行使用メモリ 12,356 KB
最終ジャッジ日時 2023-09-30 16:14:26
合計ジャッジ時間 6,181 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
11,172 KB
testcase_01 AC 40 ms
11,396 KB
testcase_02 AC 43 ms
11,152 KB
testcase_03 AC 204 ms
12,296 KB
testcase_04 AC 239 ms
12,356 KB
testcase_05 AC 245 ms
12,092 KB
testcase_06 AC 245 ms
11,968 KB
testcase_07 AC 245 ms
12,076 KB
testcase_08 AC 252 ms
12,144 KB
testcase_09 AC 242 ms
11,880 KB
testcase_10 AC 47 ms
11,508 KB
testcase_11 AC 47 ms
11,096 KB
testcase_12 AC 48 ms
11,088 KB
testcase_13 AC 47 ms
11,092 KB
testcase_14 AC 50 ms
11,492 KB
testcase_15 AC 45 ms
11,176 KB
testcase_16 AC 43 ms
11,264 KB
testcase_17 AC 41 ms
11,188 KB
testcase_18 AC 43 ms
11,084 KB
testcase_19 AC 41 ms
11,088 KB
testcase_20 AC 40 ms
11,092 KB
testcase_21 AC 40 ms
11,100 KB
testcase_22 AC 45 ms
11,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
using namespace std;
template<class T> ostream& operator << (ostream &s, vector<T> &P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

const int MAX = 1e5 + 1;
vector<int> X(MAX + 10);
vector<vector<int>> fact(MAX + 10,vector<int>{});

signed main(){
    int Q;
    cin>>Q;
    vector<int> Query(Q);
    rep(i,Q){cin>>Query[i];}
    rep1(i,MAX){X[i] = i * i + 1;}
    rep1(i,MAX){
        if (X[i] == 1)continue;
        else{
            int p = X[i];
            for (int j = i;j <= MAX; j += p){
               while(X[j] % p == 0){X[j]/= p;fact[j].push_back(p);}
            }
            for (int j = p - (i % p); j <= MAX; j+= p){
                while(X[j] % p == 0){X[j]/= p;fact[j].push_back(p);}            
            }
        }
    }

    for (int idx:Query){
        sort(ALL(fact[idx]));
        cout << fact[idx] << endl;
    }
  
    return 0;
}
0