#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template vector naive_convolution(const vector &u, const vector &v){ int n = u.size(), m = v.size(); vector ans(n+m-1); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ ans[i+j] += u[i]*v[j]; } } return ans; } /** * f(x) = g(x)*h(x) + r(x)となる(h(x), r(x))を求めます */ template pair, vector> naive_divide(vector f, const vector &g){ int n = f.size()-1; int m = g.size()-1; if(n < m) return make_pair(vector(1, T(0)), f); int k = n-m; vector h(k+1); T iv = T(1)/g[m]; for(int i = k; i >= 0; i--){ h[i] = f[i+m]*iv; for(int j = 0; j <= m; j++){ f[i+j] -= g[j]*h[i]; } } return make_pair(h, f); } using mint = atcoder::modint998244353; /** * aで表される多項式にxを代入したときの値を返します。 */ mint calc(vector a, mint x){ mint cur = 1; mint ans = 0; for(auto b : a){ ans += b*cur; cur *= x; } return ans; } /** * f(x_i) = y_iを満たす多項式を返します(O(N^2)) * verified: https://atcoder.jp/contests/abc137/submissions/20140907 */ vector lagrange_interpolation(vector x, vector y){ assert(x.size() == y.size()); int n = x.size(); vector> dp(2, vector(n+1)); dp[0][0] = x[0]*(-1); dp[0][1] = 1; for(int i = 1; i < n; i++){ int cur = i%2, prev = (i+1)%2; dp[cur][0] = dp[prev][0]*x[i]*(-1); for(int j = 1; j <= i+1; j++){ dp[cur][j] = dp[prev][j-1]-dp[prev][j]*x[i]; } } vector f(n+1); for(int i = 0; i <= n; i++) f[i] = dp[(n-1)%2][i]; vector ans(n); for(int i = 0; i < n; i++){ mint prod = 1; for(int j = 0; j < n; j++){ if(i != j) prod *= (x[i]-x[j]); } // (x-x[i])*q = f vector q(n); q[n-1] = 1; for(int j = n-1; j >= 1; j--){ q[j-1] = x[i]*q[j]+f[j]; } mint coef = y[i]*prod.inv(); for(int j = 0; j < n; j++) ans[j] += coef*q[j]; } return ans; } ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, X; cin >> n >> X; vector x(n), y(n); for(int i = 0; i < n; i++){ int xx; cin >> xx; x[i] = xx; int yy; cin >> yy; y[i] = yy; } vector p(n); vector p_inv(n); for(int i = 0; i < n; i++){ p[i] = 1; for(int j = 0; j < n; j++){ if(i == j) continue; p[i] *= x[i]-x[j]; } p_inv[i] = p[i].inv(); } vector sum(n); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i != j) { sum[j] += y[j]; sum[i] -= p[i]*p_inv[j]*y[j]; } } } auto ans = lagrange_interpolation(x, sum); cout << calc(ans, mint(X)) << endl; }