結果
問題 |
No.1409 Simple Math in yukicoder
|
ユーザー |
![]() |
提出日時 | 2021-02-26 22:49:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,713 bytes |
コンパイル時間 | 1,163 ms |
コンパイル使用メモリ | 97,128 KB |
最終ジャッジ日時 | 2025-01-19 06:26:24 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 1 WA * 57 |
コンパイルメッセージ
In function ‘T pow(T, ll, T) [with T = int]’, inlined from ‘void solve()’ at main.cpp:61:26: main.cpp:39:21: warning: ‘a’ may be used uninitialized [-Wmaybe-uninitialized] 39 | ans *= tmp; | ~~~~^~~~~~ main.cpp: In function ‘void solve()’: main.cpp:52:9: note: ‘a’ was declared here 52 | int a; | ^
ソースコード
#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<int> a){ assert(a.size() == x); int p = x*v+1; vector<int> tmp(x, 1); for(int i = 1; i <= x; i++){ for(int j = 0; j < x; j++) tmp[j] = (tmp[j]*a[j])%p; int sum = accumulate(tmp.begin(), tmp.end(), 0); if(i == x) assert(sum%p == 0); else assert(sum%p == x); } } template <typename T> T pow(T a, ll n, T MOD) { T ans = 1; T 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; int a; for(int i = 2; i < p; i++){ if(pow(i, v, p) != 1){ a = i; break; } } vector<int> 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(); }