結果

問題 No.1409 Simple Math in yukicoder
ユーザー pockynypockyny
提出日時 2021-02-26 23:49:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 83,916 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-10 14:49:00
合計ジャッジ時間 29,703 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
13,184 KB
testcase_01 AC 55 ms
13,184 KB
testcase_02 AC 49 ms
13,056 KB
testcase_03 AC 53 ms
13,184 KB
testcase_04 AC 52 ms
13,312 KB
testcase_05 AC 50 ms
13,272 KB
testcase_06 AC 52 ms
13,280 KB
testcase_07 AC 59 ms
13,284 KB
testcase_08 AC 82 ms
13,184 KB
testcase_09 AC 62 ms
13,184 KB
testcase_10 AC 75 ms
13,440 KB
testcase_11 AC 88 ms
13,184 KB
testcase_12 AC 75 ms
13,056 KB
testcase_13 AC 60 ms
13,184 KB
testcase_14 AC 63 ms
13,312 KB
testcase_15 AC 67 ms
13,312 KB
testcase_16 AC 55 ms
13,312 KB
testcase_17 AC 91 ms
13,056 KB
testcase_18 AC 72 ms
13,184 KB
testcase_19 AC 77 ms
13,184 KB
testcase_20 AC 71 ms
13,184 KB
testcase_21 AC 55 ms
13,280 KB
testcase_22 AC 75 ms
13,184 KB
testcase_23 AC 54 ms
13,312 KB
testcase_24 AC 44 ms
13,184 KB
testcase_25 AC 69 ms
13,184 KB
testcase_26 AC 66 ms
13,300 KB
testcase_27 AC 84 ms
13,184 KB
testcase_28 AC 90 ms
13,056 KB
testcase_29 AC 102 ms
13,312 KB
testcase_30 AC 92 ms
13,056 KB
testcase_31 AC 88 ms
13,312 KB
testcase_32 AC 80 ms
13,312 KB
testcase_33 AC 85 ms
13,056 KB
testcase_34 AC 85 ms
13,184 KB
testcase_35 AC 84 ms
13,312 KB
testcase_36 AC 83 ms
13,312 KB
testcase_37 AC 124 ms
13,056 KB
testcase_38 AC 138 ms
13,056 KB
testcase_39 AC 131 ms
13,312 KB
testcase_40 AC 139 ms
13,184 KB
testcase_41 AC 136 ms
13,184 KB
testcase_42 AC 144 ms
13,440 KB
testcase_43 AC 136 ms
13,312 KB
testcase_44 AC 136 ms
13,056 KB
testcase_45 AC 146 ms
13,184 KB
testcase_46 AC 138 ms
13,312 KB
testcase_47 AC 141 ms
13,160 KB
testcase_48 AC 137 ms
13,312 KB
testcase_49 AC 133 ms
13,056 KB
testcase_50 AC 146 ms
13,312 KB
testcase_51 AC 139 ms
13,272 KB
testcase_52 AC 146 ms
13,184 KB
testcase_53 AC 143 ms
13,184 KB
testcase_54 AC 143 ms
13,184 KB
testcase_55 AC 141 ms
13,184 KB
testcase_56 AC 146 ms
13,312 KB
testcase_57 AC 171 ms
13,056 KB
testcase_58 AC 175 ms
13,312 KB
testcase_59 AC 172 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll pw(ll a,ll x,ll mod){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

vector<int> di[100010] = {};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    for(int i=2;i<=100000;i++){
        for(int j=2*i;j<=100000;j+=i){
            di[j].push_back(i);
        }
    }
    while(t){
        t--;
        int i,j,x,v; cin >> v >> x;
        if(v*x==1){
            cout << 1 << endl;
            continue;
        }
        int r = -1,p = x*v + 1;
        for(i=2;i<=x*v;i++){
            bool f = true;
            for(int num: di[p - 1]){
                if(pw(i,num,p)==1) f = false;
            }
            if(f){
                r = i; break;
            }
        }
        vector<int> ans;
        for(i=1;i<=x;i++) ans.push_back(pw(r,i*v,p));
        sort(ans.begin(),ans.end());
        for(i=0;i<x;i++) cout << ans[i] << " ";
        cout << endl;
    }
}
0