結果
問題 | No.1409 Simple Math in yukicoder |
ユーザー |
![]() |
提出日時 | 2021-02-28 16:09:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 2,142 bytes |
コンパイル時間 | 986 ms |
コンパイル使用メモリ | 100,544 KB |
最終ジャッジ日時 | 2025-01-19 08:09:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 58 |
ソースコード
#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();}