結果

問題 No.1409 Simple Math in yukicoder
ユーザー milanis48663220milanis48663220
提出日時 2021-02-28 16:09:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 2,142 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 103,828 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 16:00:35
合計ジャッジ時間 29,355 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 18 ms
6,944 KB
testcase_08 AC 59 ms
6,940 KB
testcase_09 AC 17 ms
6,940 KB
testcase_10 AC 49 ms
6,940 KB
testcase_11 AC 59 ms
6,944 KB
testcase_12 AC 46 ms
6,940 KB
testcase_13 AC 18 ms
6,940 KB
testcase_14 AC 15 ms
6,944 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 22 ms
6,940 KB
testcase_17 AC 81 ms
6,940 KB
testcase_18 AC 38 ms
6,944 KB
testcase_19 AC 46 ms
6,940 KB
testcase_20 AC 36 ms
6,940 KB
testcase_21 AC 29 ms
6,940 KB
testcase_22 AC 51 ms
6,948 KB
testcase_23 AC 13 ms
6,940 KB
testcase_24 AC 9 ms
6,940 KB
testcase_25 AC 48 ms
6,940 KB
testcase_26 AC 56 ms
6,940 KB
testcase_27 AC 90 ms
6,944 KB
testcase_28 AC 93 ms
6,940 KB
testcase_29 AC 89 ms
6,944 KB
testcase_30 AC 94 ms
6,940 KB
testcase_31 AC 90 ms
6,940 KB
testcase_32 AC 87 ms
6,944 KB
testcase_33 AC 87 ms
6,940 KB
testcase_34 AC 84 ms
6,944 KB
testcase_35 AC 91 ms
6,940 KB
testcase_36 AC 91 ms
6,940 KB
testcase_37 AC 195 ms
6,944 KB
testcase_38 AC 207 ms
6,940 KB
testcase_39 AC 194 ms
6,944 KB
testcase_40 AC 208 ms
6,940 KB
testcase_41 AC 196 ms
6,940 KB
testcase_42 AC 194 ms
6,940 KB
testcase_43 AC 194 ms
6,940 KB
testcase_44 AC 195 ms
6,940 KB
testcase_45 AC 201 ms
6,940 KB
testcase_46 AC 205 ms
6,940 KB
testcase_47 AC 198 ms
6,940 KB
testcase_48 AC 196 ms
6,944 KB
testcase_49 AC 202 ms
6,940 KB
testcase_50 AC 192 ms
6,944 KB
testcase_51 AC 194 ms
6,940 KB
testcase_52 AC 197 ms
6,940 KB
testcase_53 AC 192 ms
6,944 KB
testcase_54 AC 194 ms
6,940 KB
testcase_55 AC 196 ms
6,944 KB
testcase_56 AC 195 ms
6,944 KB
testcase_57 AC 227 ms
6,944 KB
testcase_58 AC 217 ms
6,944 KB
testcase_59 AC 208 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

void validate(int v, int x, vector<ll> a){
    assert(a.size() == x);
    int p = x*v+1;
    vector<int> tmp(x, 1);
    for(int i = 1; i <= x; i++){
        // cout << i << ' ';
        for(int j = 0; j < x; j++) tmp[j] = (tmp[j]*a[j])%p;
        int sum = accumulate(tmp.begin(), tmp.end(), 0);
        // cout << i << ' ' << x << endl;
        // for(int s : tmp) cout << s << ' ';
        // cout << endl;
        // cout << sum%p << ' ' << p << endl;
        if(i == x) assert(sum%p == x);
        else assert(sum%p == 0);
    }
}

ll pow(ll a, ll n, ll MOD) {
	ll ans = 1;
	ll tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}


void solve(){
    int v, x; cin >> v >> x;
    int p = x*v+1;
    if(x == 1){
        cout << 1 << endl;
        return;
    }
    int a = -1;
    for(int i = 2; i < p; i++){
        bool ok = true;
        ll pw = pow(i, v, p);
        ll tmp = 1;
        for(int j = 1; j < x; j++){
            tmp = (tmp*pw)%p;
            if(tmp == 1) ok = false;
        }
        if(ok){
            a = i;
            break;
        }
    }
    assert(a != -1);
    vector<ll> ans;
    for(int i = 0; i < x; i++){
        ans.push_back(pow(a, i*v, p));
    }
    sort(ans.begin(), ans.end());
    validate(v, x, ans);
    for(int x : ans) cout << x << ' ';
    cout << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0