結果
| 問題 | No.2558 中国剰余定理 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-24 00:48:39 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 348µs | |
| コード長 | 2,289 bytes |
| 記録 | |
| コンパイル時間 | 1,481 ms |
| コンパイル使用メモリ | 213,988 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-24 00:48:43 |
| 合計ジャッジ時間 | 3,417 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class S> using v = vector<S>;
template <class S> using vv = vector<vector<S>>;
template <class S> using vvv = vector<vector<vector<S>>>;
#define rep(...) overload_rep(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define overload_rep(_1, _2, _3, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vvvi vector<vector<vector<int>>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define el '\n'
#define sp ' '
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
template<class T>
bool chmin(T &a, const T &b){
if (b < a){ a = b; return true; }
return false;
}
template<class T>
bool chmax(T &a, const T &b){
if (b > a){ a = b; return true; }
return false;
}
using mtup = tuple<int, int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const int mod = 998244353;
// const int mod = 1e9 + 7;
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll g = extgcd(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return g;
}
ll mod_inv(ll a, ll mod) {
ll x, y;
extgcd(a, mod, x, y);
x %= mod;
if (x < 0) x += mod;
return x;
}
ll CRT(vi& a, vi&m){
ll M = 1, res = 0;
for(auto i: m) M *= i;
for(int i = 0; i < a.size(); ++i){
ll Mi = M / m[i];
ll xi = mod_inv(Mi, m[i]);
ll ei = Mi * xi % M;
res = (res + a[i] * ei % M) % M;
}
return res;
}
vi f(vi a){
int n = 2;
int m = a.size();
vi res = a;
rep(i, n - 1){
rep(j, m){
res[j] = a[res[j] - 1];
}
a = res;
}
return res;
}
int main(){
//高速化
//ここから
vi a(2), mod(2);
cin >> mod[0] >> mod[1];
cin >> a[0] >> a[1];
cout << CRT(a, mod) << el;
}
/*
cppt
cppt_ge
seg, bit, uf
g++ main.cpp -O2 -std=c++17
./a.out
*/