//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<class T>
using vec = vector<T>;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef KoRoVa
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif
const int max_n = 1e6 + 11, inf = 1000111222;
const int mod = 1e9 + 7;
inline void inc(int &x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
inline void dec(int &x, int y) {
x -= y;
if (x < 0) {
x += mod;
}
}
inline int neg (int x) {
return x ? mod - x : 0;
}
inline int mul(int x, int y) {
return (1LL * x * y) % mod;
}
int power(int x, int y) {
if (y < 0) {
y += mod - 1;
}
if (y == 0) {
return 1;
}
if (y % 2 == 0) {
return power(mul(x, x), y / 2);
}
return mul(x, power(x, y - 1));
}
inline int inv(int x) {
return power(x, mod - 2);
}
// new mint part
inline int divide (int x, int y) {
return mul(x, inv(y));
}
struct mint {
#define oper_apply(op, f) mint& operator op (const mint &x) {f(val, x.val); return *this;}
#define oper_apply_const(op, f) mint operator op (const mint &x) const {mint tmp = *this; f(tmp.val, x.val); return tmp;}
#define oper_return(op, f) mint& operator op (const mint &x) {val = f(val, x.val); return *this;}
#define oper_return_const(op, f) mint operator op (const mint &x) const {return mint(f(val, x.val));}
int val;
mint(int x = 0) : val(x) {}
oper_apply(+=, inc);
oper_apply_const(+, inc);
oper_apply(-=, dec);
oper_apply_const(-, dec);
oper_return(*=, mul);
oper_return_const(*, mul);
oper_return(/=, divide);
oper_return_const(/, divide);
oper_return(^=, power);
oper_return_const(^, power);
};
inline mint calc (int n, mint s, mint a) {
mint res = (s + a) ^ n;
res -= s ^ n;
return res;
}
inline mint calc2 (int n, mint s, mint a) {
mint res = a * mint(n) * ((a + s) ^ (n - 1));
return res;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k, m;
cin >> n >> k >> m;
vector <mint> p(m + 1);
mint inv_k = mint(1) / mint(k);
mint ans = 0;
mint sum = 0;
auto add = [&] (int pos, mint val) {
if (pos <= m) {
p[pos] += val;
sum += val * (m - pos);
}
};
add(0, 1);
add(1, mint(0) - 1);
mint pref = 0;
for (int i = 0; i < m; i++) {
pref += p[i];
sum -= pref;
// for (int j = i + 1; j < m; j++) {
// sum += p[j];
// }
mint can = min(k, m - i - 1);
can *= inv_k;
if (pref.val) {
if (can.val == 1) {
ans += calc2(n, sum, pref);
} else {
ans += (calc(n, sum, pref * can) - calc(n, sum, pref)) / (can - 1);
}
}
// LOG(pref.val, (pref * 16).val, sum.val);
mint val = pref * inv_k;
add(i + 1, val);
add(i + k + 1, mint(0) - val);
}
cout << ans.val << '\n';
// LOG((mint(461) / mint(256)).val); 319876872
}
/*
KoRoVa!
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | //#pragma GCC optimize("Ofast", "unroll-loops") //#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4") #include <bits/stdc++.h> #define all(a) a.begin(),a.end() #define len(a) (int)(a.size()) #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; template<class T> using vec = vector<T>; template<typename T> bool umin(T &a, T b) { if (b < a) { a = b; return true; } return false; } template<typename T> bool umax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #ifdef KoRoVa #define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false) #define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); } #else #define DEBUG while (false) #define LOG(...) #endif const int max_n = 1e6 + 11, inf = 1000111222; const int mod = 1e9 + 7; inline void inc(int &x, int y) { x += y; if (x >= mod) { x -= mod; } } inline void dec(int &x, int y) { x -= y; if (x < 0) { x += mod; } } inline int neg (int x) { return x ? mod - x : 0; } inline int mul(int x, int y) { return (1LL * x * y) % mod; } int power(int x, int y) { if (y < 0) { y += mod - 1; } if (y == 0) { return 1; } if (y % 2 == 0) { return power(mul(x, x), y / 2); } return mul(x, power(x, y - 1)); } inline int inv(int x) { return power(x, mod - 2); } // new mint part inline int divide (int x, int y) { return mul(x, inv(y)); } struct mint { #define oper_apply(op, f) mint& operator op (const mint &x) {f(val, x.val); return *this;} #define oper_apply_const(op, f) mint operator op (const mint &x) const {mint tmp = *this; f(tmp.val, x.val); return tmp;} #define oper_return(op, f) mint& operator op (const mint &x) {val = f(val, x.val); return *this;} #define oper_return_const(op, f) mint operator op (const mint &x) const {return mint(f(val, x.val));} int val; mint(int x = 0) : val(x) {} oper_apply(+=, inc); oper_apply_const(+, inc); oper_apply(-=, dec); oper_apply_const(-, dec); oper_return(*=, mul); oper_return_const(*, mul); oper_return(/=, divide); oper_return_const(/, divide); oper_return(^=, power); oper_return_const(^, power); }; inline mint calc (int n, mint s, mint a) { mint res = (s + a) ^ n; res -= s ^ n; return res; } inline mint calc2 (int n, mint s, mint a) { mint res = a * mint(n) * ((a + s) ^ (n - 1)); return res; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int n, k, m; cin >> n >> k >> m; vector <mint> p(m + 1); mint inv_k = mint(1) / mint(k); mint ans = 0; mint sum = 0; auto add = [&] (int pos, mint val) { if (pos <= m) { p[pos] += val; sum += val * (m - pos); } }; add(0, 1); add(1, mint(0) - 1); mint pref = 0; for (int i = 0; i < m; i++) { pref += p[i]; sum -= pref; // for (int j = i + 1; j < m; j++) { // sum += p[j]; // } mint can = min(k, m - i - 1); can *= inv_k; if (pref.val) { if (can.val == 1) { ans += calc2(n, sum, pref); } else { ans += (calc(n, sum, pref * can) - calc(n, sum, pref)) / (can - 1); } } // LOG(pref.val, (pref * 16).val, sum.val); mint val = pref * inv_k; add(i + 1, val); add(i + k + 1, mint(0) - val); } cout << ans.val << '\n'; // LOG((mint(461) / mint(256)).val); 319876872 } /* KoRoVa! */ |
English