이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long lint;
const int MAXN = 100005;
int n;
vector<int> basis[205];
lint ans[205];
lint ipow(lint x, lint p){
	int mod = n;
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}
void upload(vector<int> &v){
	for(int i=0; i<n; i++){
		if(v[i] == 0) continue;
		if(basis[i].empty()){
			basis[i] = v;
			break;
		}
		int gyesu = v[i] * ipow(basis[i][i], n-2) % n;
		for(int j=0; j<n; j++){
			v[j] += n - gyesu * basis[i][j] % n;
			v[j] %= n;
		}
	}
}
int main(){
	cin >> n;
	for(int i=1; i<n; i++){
		vector<int> ws;
		ws.push_back(1);
		for(int j=1; j<n; j++){
			ws.push_back(ws.back() * i % n);
		}
		ws[i] += n - 1;
		ws[i] %= n;
		upload(ws);
	}
	int idp = -1;
	for(int i=0; i<n; i++){
		if(basis[i].empty()) idp = i;
	}
	assert(idp == n-1);
	for(int i=0; i<n; i++){
		ans[n-1] = i;
		for(int j=n-2; j>=0; j--){
			ans[j] = 0;
			for(int k=0; k<n; k++){
				ans[j] -= ans[k] * basis[j][k];
			}
			ans[j] %= n;
			ans[j] += n;
			ans[j] %= n;
			ans[j] *= ipow(basis[j][j], n-2);
			ans[j] %= n;
		}
		for(int i=n-1; i>=0; i--) printf("%lld ", ans[i]);
		puts("");
	}
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |