QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113863#5547. Short FunctionPetroTarnavskyiWA 1ms3536kbC++172.1kb2023-06-19 19:32:372023-06-19 19:32:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 19:32:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3536kb
  • [2023-06-19 19:32:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int mod = 998244353;
int add(int a, int b){
	return (a + b > mod) ? (a + b - mod) : (a + b);
}
int sub(int a, int b){
	return (a - b < 0) ? (a - b + mod) : (a - b);
}
int mult(int a, int b){
	return 1LL* a * b % mod;
}
int binpow(int a, int n){
	int res = 1;
	while(n){
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

int inv(int x)
{
	return binpow(x, mod - 2);
}
int sub2(int a, int b, int md){
	return (a + md - b) % md;
}
int mult2(int a, int b, int md){
	return 1ll * a * b % md;
}
int binpow2(int a, int k, int md){
	int res = 1;
	while(k){
		if(k & 1)
			res = mult2(res, a, md);
		a = mult2(a, a, md);
		k /= 2;
	}
	return res;
}
int inv2(int a, int md){
	int val = md;
	int x = md;
	for(int p = 2; p * p <= x; p++)
		if(x % p == 0){
			val -= val / p;
			while(x % p == 0)
				x /= p;
		}
	if(x != 1)
		val -= val / x;
	
	return binpow2(a, val - 1, md);
}




int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	VI a(n);
	FOR (i, 0, n) cin >> a[i];
	VI pr(n + 1, 1);
	VI ipr(n + 1, 1);
	FOR (i, 0, n) 
	{
		pr[i + 1] = mult(pr[i], a[i]);
		ipr[i + 1] = inv(pr[i + 1]);
	}
	int all = pr[n];
	int pos = binpow2(2, k, n);
	
	int cnt = mult2(sub2(binpow2(2, k, mod - 1), pos, mod - 1), inv2(n, mod - 1), mod - 1);
	
	
	int pachka = binpow(all, cnt);
	
	FOR (i, 0, n)
	{
		//[i, pos)
		int res = pachka;
		if(pos < i){
			int cur = pr[pos];
			cur = mult(cur, mult(all, ipr[i]));
			res = mult(res, cur);
		}else{
			res = mult(res, mult(pr[pos], ipr[i]));
		}
		cout << res << " ";
		pos = (pos + 1) % n;
	}
	cout << endl;
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3536kb

input:

5 2
1 2 3 4 5

output:

24 120 60 40 30 

result:

ok 5 number(s): "24 120 60 40 30"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3432kb

input:

8 3
12 5 16 14 10 6 9 2

output:

395868439 395868439 395868439 395868439 395868439 395868439 395868439 395868439 

result:

wrong answer 1st numbers differ - expected: '14515200', found: '395868439'