QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188680#6887. Data GenerationmeomeoWA 48ms3608kbC++141.6kb2023-09-26 11:11:102023-09-26 11:11:10

Judging History

你现在查看的是最新测评结果

  • [2023-09-26 11:11:10]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:3608kb
  • [2023-09-26 11:11:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long

using namespace std;

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int mod = 998244353; 

ll modpow(ll b, ll e) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}

template<class T, int N> struct Matrix {
	typedef Matrix M;
	array<array<T, N>, N> d{};
	M operator*(const M& m) const {
		M a;
		rep(i,0,N) rep(j,0,N)
			rep(k,0,N) a.d[i][j] += d[i][k]*m.d[k][j];
		return a;
	}
	vector<T> operator*(const vector<T>& vec) const {
		vector<T> ret(N);
		rep(i,0,N) rep(j,0,N) ret[i] += d[i][j] * vec[j];
		return ret;
	}
	M operator^(ll p) const {
		assert(p >= 0);
		M a, b(*this);
		rep(i,0,N) a.d[i][i] = 1;
		while (p) {
			if (p&1) a = a*b;
			b = b*b;
			p >>= 1;
		}
		return a;
	}
};

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	int t;

	cin >> t;

	while (t--) {
		int n, m;

		cin >> n >> m;

		if (m == 0 || n == 1) {
			cout << 0 << "\n";
			continue;	
		}

		Matrix<int, 2> a;

		int d = modpow(n*n, mod-2);
		a.d[0][0] = (((n * n - 2) * d) % mod + mod) % mod;
		a.d[0][1] = (2 * d) % mod;
		a.d[1][0] = (2 * (n - 1) * d) % mod;
		a.d[1][1] = ((((n-1) * (n-1)) % mod) * d) % mod;

		a = a ^ m;
		int res = (a.d[1][0]) % mod;
		res = (res * n) % mod;

		cout << res << "\n";
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 48ms
memory: 3608kb

input:

100000
19491001 19491001
999999999449325353 939501148
400027352 999999998707619026
999999998353720210 999999999303057191
1879045722 1874448608
999999998385974740 1710466660
109045962 999999998020190078
999999998217418921 999999998898659805
999999999999986692 999999998389218199
351693073 2130408866
1...

output:

366934168
430661604
222500068
683732585
-751206676
-654856285
-22387548
-660993465
258365101
50747494
141559719
-307625811
572498197
-426706648
179238093
0
138408220
0
846294457
249561089
0
-615251827
-350715245
808292935
-504089180
-488953243
942057322
0
739349740
0
0
0
-235995658
510042643
0
-8722...

result:

wrong answer 1st lines differ - expected: '79256423', found: '366934168'