結果

問題 No.1161 Many Powers
ユーザー FF256grhyFF256grhy
提出日時 2020-08-12 04:29:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 6,550 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 204,104 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 13:42:01
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 5 ms
5,248 KB
testcase_06 AC 5 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 33 ms
5,248 KB
testcase_09 AC 38 ms
5,248 KB
testcase_10 AC 16 ms
5,248 KB
testcase_11 AC 28 ms
5,248 KB
testcase_12 AC 14 ms
5,248 KB
testcase_13 AC 44 ms
5,248 KB
testcase_14 AC 67 ms
5,248 KB
testcase_15 AC 58 ms
5,248 KB
testcase_16 AC 75 ms
5,248 KB
testcase_17 AC 50 ms
5,248 KB
testcase_18 AC 36 ms
5,248 KB
testcase_19 AC 21 ms
5,248 KB
testcase_20 AC 79 ms
5,248 KB
testcase_21 AC 21 ms
5,248 KB
testcase_22 AC 81 ms
5,248 KB
testcase_23 AC 2 ms
5,248 KB
testcase_24 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
// 以下、入出力関係のテンプレ案のテスト
auto * IS = & cin;
// input elements (as a tuple)
template<typename U, int I> void in_(U & t) { }
template<typename U, int I, typename A, typename ... B> void in_(U & t) { (* IS) >> get<I>(t); in_<U, I + 1, B ...>(t); }
template<typename ... T> auto in() { tuple<T ...> t; in_<tuple<T ...>, 0, T ...>(t); return t; }
// input a array
template<typename T, int N> auto ain() { array<T, N> a; inc(i, N) { (* IS) >> a[i]; } return a; }
// input a (multi-dimensional) vector
template<typename T> T vin() { return * istream_iterator<T>(* IS); }
template<typename T, typename N, typename ... M> auto vin(N n, M ... m) {
	vector<decltype(vin<T, M ...>(m ...))> v(n); inc(i, n) { v[i] = vin<T, M ...>(m ...); } return v;
}
// input multi-column (as a tuple of vector)
template<typename U, int I> void colin_(U & t) { }
template<typename U, int I, typename A, typename ... B> void colin_(U & t) {
	get<I>(t).emplace_back(* istream_iterator<A>(* IS)); colin_<U, I + 1, B ...>(t);
}
template<typename ... T> auto colin(int n) {
	tuple<vector<T> ...> t; inc(i, n) { colin_<tuple<vector<T> ...>, 0, T ...>(t); } return t;
}
auto * OS = & cout;
string SP = " ", LN = "\n";
// output elements
void out() { (* OS) << LN << flush; }
template<typename A                > void out(A && a            ) { (* OS) << a      ; out(     ); }
template<typename A, typename ... B> void out(A && a, B && ... b) { (* OS) << a << SP; out(b ...); }
// output a (multi-dimensional) vector
template<typename T> ostream & operator<<(ostream & os, vector<T> const & v) {
	inc(i, v.size()) { os << (i == 0 ? "" : SP) << v[i]; } return os << flush;
}
template<typename T> void vout_(T && v) { (* OS) << v; }
template<typename T, typename A, typename ... B> void vout_(T && v, A a, B ... b) {
	for(auto && w: v) { vout_(w, b ...); (* OS) << a; }
}
template<typename T, typename ... A> void vout(T && v, A ... a) { vout_(v, a ...); out(); }

// ---- ----

template<int N = 0> class DynModInt {
private:
	static LL M;
	LL v;
	pair<LL, LL> ext_gcd(LL a, LL b) {
		if(b == 0) { assert(a == 1); return { 1, 0 }; }
		auto p = ext_gcd(b, a % b);
		return { p.SE, p.FI - (a / b) * p.SE };
	}
public:
	DynModInt() { v = 0; }
	DynModInt(LL vv) { assert(M > 0); v = vv; if(abs(v) >= M) { v %= M; } if(v < 0) { v += M; } }
	static void set_M(LL m) { M = m; }
	static LL get_M() { return M; }
	LL get_v() { return v; }
	DynModInt inv() { return ext_gcd(M, v).SE; }
	DynModInt exp(LL b) {
		DynModInt p = 1, a = v; if(b < 0) { a = a.inv(); b = -b; }
		while(b) { if(b & 1) { p *= a; } a *= a; b >>= 1; }
		return p;
	}
	friend bool        operator< (DynModInt   a, DynModInt   b) { return (a.v <  b.v); }
	friend bool        operator> (DynModInt   a, DynModInt   b) { return (a.v >  b.v); }
	friend bool        operator<=(DynModInt   a, DynModInt   b) { return (a.v <= b.v); }
	friend bool        operator>=(DynModInt   a, DynModInt   b) { return (a.v >= b.v); }
	friend bool        operator==(DynModInt   a, DynModInt   b) { return (a.v == b.v); }
	friend bool        operator!=(DynModInt   a, DynModInt   b) { return (a.v != b.v); }
	friend DynModInt   operator+ (DynModInt   a               ) { return DynModInt(+a.v); }
	friend DynModInt   operator- (DynModInt   a               ) { return DynModInt(-a.v); }
	friend DynModInt   operator+ (DynModInt   a, DynModInt   b) { return DynModInt(a.v + b.v); }
	friend DynModInt   operator- (DynModInt   a, DynModInt   b) { return DynModInt(a.v - b.v); }
	friend DynModInt   operator* (DynModInt   a, DynModInt   b) { return DynModInt(a.v * b.v); }
	friend DynModInt   operator/ (DynModInt   a, DynModInt   b) { return a * b.inv(); }
	friend DynModInt   operator^ (DynModInt   a, LL          b) { return a.exp(b); }
	friend DynModInt & operator+=(DynModInt & a, DynModInt   b) { return (a = a + b); }
	friend DynModInt & operator-=(DynModInt & a, DynModInt   b) { return (a = a - b); }
	friend DynModInt & operator*=(DynModInt & a, DynModInt   b) { return (a = a * b); }
	friend DynModInt & operator/=(DynModInt & a, DynModInt   b) { return (a = a / b); }
	friend DynModInt & operator^=(DynModInt & a, LL          b) { return (a = a ^ b); }
	friend istream   & operator>>(istream   & s, DynModInt & b) { s >> b.v; b = DynModInt(b.v); return s; }
	friend ostream   & operator<<(ostream   & s, DynModInt   b) { return (s << b.v); }
};
template<int N> LL DynModInt<N>::M = 0;

// ----

using DMI = DynModInt<>;

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

// { x in (l, r] | x mod m = a } の要素数
LL cmCI(LL l, LL r, LL m, LL a) { assert(m > 0); return max(0LL, fl(r - a, m) - fl(l - a, m)); }
LL cmCD(LL l, LL r, LL m, LL a) { return cmCI(l    , r - 1, m, a); }
LL cmII(LL l, LL r, LL m, LL a) { return cmCI(l - 1, r    , m, a); }
LL cmID(LL l, LL r, LL m, LL a) { return cmCI(l - 1, r - 1, m, a); }

int main() {
	auto [a, b, c] = ain<LL, 3>();
	DMI::set_M(c);
	DMI ans = 0;
	inc(i, c) { ans += cmII(1, a, c, i) * (DMI(i) ^ b); }
	out(ans);
}
0