QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203614#7562. Except Oneucup-team2112#AC ✓0ms4076kbC++174.5kb2023-10-06 18:41:502023-10-06 18:41:51

Judging History

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

  • [2023-10-06 18:41:51]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:4076kb
  • [2023-10-06 18:41:50]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;

template<class A, class B> string to_string(const pair<A, B> &p);
template<class A, class B, class C> string to_string(const tuple<A, B, C> &p);
template<class A, class B, class C, class D> string to_string(const tuple<A, B, C, D> &p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A, class T = typename A::value_type> string to_string(const A &v) {
	bool first = 1;
	string res = "{";
	for (const auto &x: v) {
		if (!first) res += ", ";
		first = 0;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template<class A, class B> string to_string(const pair<A, B> &p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C> string to_string(const tuple<A, B, C> &p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template<class A, class B, class C, class D> string to_string(const tuple<A, B, C, D> &p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
template<class H, class... T> void debug_out(const H& h, const T&... t) {
	cerr << " " << to_string(h);
	debug_out(t...);
}
#ifndef ONLINE_JUDGE
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
	#define debug(...) if (0) puts("No effect.")
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

/**
 * Author: Yuhao Yao
 * Date: 23-05-11
 * Description: Modular integer with $mod \le 2^{31} - 1$. Note that there are several advantages to use this code:
   1. You do not need to keep writing $\%\, mod$;
   2. It is good to use this struct when doing Gaussian Elimination / Fast Walsh-Hadamard Transform;
   3. Sometimes the input number is greater than $mod$ and this code handles it.
  Do not write things like $mint\{1 / 3\}.pow(10)$ since $1 / 3$ simply equals $0$.
  Do not write things like $mint\{a * b\}$ where $a$ and $b$ are int since you might first have integer overflow.
 * Usage: Define the followings globally:
   const int mod = 998244353;
   using mint = MInt<mod>;
 * Status: tested on https://ac.nowcoder.com/acm/contest/33191/F.
 */
template<const unsigned &mod>
struct MInt {
	using Z = MInt;
	unsigned x; /// start-hash
	MInt(ll a = 0): x(a % mod + mod) { if (x >= mod) x -= mod; }
	explicit operator int() const { return x; }

	Z& operator +=(Z b) { x += b.x; if (x >= mod) x -= mod; return *this; }
	Z& operator -=(Z b) { x += mod - b.x; if (x >= mod) x -= mod; return *this; }
	Z& operator *=(Z b) { x = 1ll * x * b.x % mod; return *this; }
	friend Z operator +(Z a, Z b) { return a += b; }
	friend Z operator -(Z a, Z b) { return a -= b; }
	friend Z operator -(Z a) { return Z{} - a; }
	friend Z operator *(Z a, Z b) { return a *= b; }
	/// end-hash

	// the followings are for ntt and polynomials.
	Z pow(ll k) const { /// start-hash
		Z res = 1, a = *this;
		for (; k; k >>= 1, a = a * a) if (k & 1) res = res * a;
		return res;
	}
	Z& operator /=(Z b) {
		assert(b.x != 0);
		return *this *= b.pow(mod - 2);
	}
	friend Z operator /(Z a, Z b) { return a /= b; }
	friend bool operator ==(Z a, Z b) { return a.x == b.x; }
	friend bool operator !=(Z a, Z b) { return a.x != b.x; }
	friend bool operator <(Z a, Z b) { return a.x < b.x; }

	static unsigned getMod() { return mod; } // ntt need this.
	/// end-hash

	friend istream& operator >>(istream &is, Z &a) {
		ll v; is >> v;
		a = v;
		return is;
	}
	friend string to_string(Z a) { return to_string(a.x); }
};

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	static unsigned mod = 0;
	using mint = MInt<mod>;

	int k, t; cin >> mod >> k >> t;
	mint ans = 0;
	if ((unsigned) t == mod - 2) {
		ans = mint{-1} / k;
	} else {
		ans = mint{-k}.pow(t);
	}
	printf("%d\n", (int) ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3776kb

input:

7 5 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

11 6 7

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

596620183 516846890 38276329

output:

135352707

result:

ok 1 number(s): "135352707"

Test #5:

score: 0
Accepted
time: 0ms
memory: 4036kb

input:

382744931 85302262 235496559

output:

14577469

result:

ok 1 number(s): "14577469"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

659446013 641119314 378275666

output:

290624162

result:

ok 1 number(s): "290624162"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

227 163 124

output:

189

result:

ok 1 number(s): "189"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

197 187 19

output:

62

result:

ok 1 number(s): "62"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

5 3 3

output:

3

result:

ok 1 number(s): "3"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

7 6 4

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 0ms
memory: 4072kb

input:

7 1 1

output:

6

result:

ok 1 number(s): "6"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

782371 586755 418517

output:

298550

result:

ok 1 number(s): "298550"

Test #13:

score: 0
Accepted
time: 0ms
memory: 4076kb

input:

181081 178315 76002

output:

125177

result:

ok 1 number(s): "125177"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

715019 492103 446729

output:

221541

result:

ok 1 number(s): "221541"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

238985261 199832612 162675695

output:

65826267

result:

ok 1 number(s): "65826267"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

129716453 10994076 62963738

output:

5186275

result:

ok 1 number(s): "5186275"

Test #17:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

962360593 652577122 345596237

output:

814039152

result:

ok 1 number(s): "814039152"

Test #18:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

871606937 839183139 754188014

output:

466391387

result:

ok 1 number(s): "466391387"

Test #19:

score: 0
Accepted
time: 0ms
memory: 4076kb

input:

275568091 270750503 241146839

output:

252569968

result:

ok 1 number(s): "252569968"

Test #20:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

562028473 111749710 450258818

output:

63116256

result:

ok 1 number(s): "63116256"