QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469208 | #273. 类欧几里得算法 | yaoxi_std# | 100 ✓ | 180ms | 3980kb | C++14 | 3.2kb | 2024-07-09 16:09:34 | 2024-07-09 16:09:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(fmt, ...) \
fprintf(stderr, "[%d] " fmt "\n", __LINE__, ##__VA_ARGS__)
template <class _Tx, class _Ty>
inline void chkmin(_Tx& x, const _Ty& y) {
x = min<common_type_t<_Tx, _Ty>>(x, y);
}
template <class _Tx, class _Ty>
inline void chkmax(_Tx& x, const _Ty& y) {
x = max<common_type_t<_Tx, _Ty>>(x, y);
}
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
bool Mbe;
namespace euclid {
template <class _Tp>
_Tp qpow(_Tp x, ll y) {
_Tp ret;
for (; y; y >>= 1, x = x * x) if (y & 1) ret = ret * x;
return ret;
}
template <class _Tp>
_Tp euclid_impl(ll a, ll b, ll c, ll n, const _Tp& U, const _Tp& R) {
ll m = ((i128)a * n + c) / b;
if (!m) return qpow(R, n);
return qpow(R, (b - c - 1) / a) * U *
euclid_impl(b % a, a, (b - c - 1) % a, m - 1, R, qpow(R, b / a) * U) *
qpow(R, n - ((i128)b * m - c - 1) / a);
}
template <class _Tp>
_Tp euclid(ll a, ll b, ll c, ll n, const _Tp& U, const _Tp& R) {
return qpow(U, c / b) * euclid_impl(a % b, b, c % b, n, U, qpow(U, a / b) * R);
}
} // namespace euclid
constexpr int K = 11, mod = 1e9 + 7;
int kx, ky, bnm[K][K];
ll n, a, b, c;
inline void add(int& x, int y) { x += y, x >= mod && (x -= mod); }
int qpow(int x, int y) {
int ret = 1;
for (; y; y >>= 1, x = (ll)x * x % mod)
if (y & 1) ret = (ll)ret * x % mod;
return ret;
}
struct node {
int val[K][K], sum[K][K];
node() {
memset(val, 0, sizeof(val));
memset(sum, 0, sizeof(sum));
val[0][0] = 1;
}
};
node operator*(const node& lhs, const node& rhs) {
node ret;
ret.val[0][0] = 0;
for (int i = 0; i <= kx; ++i) {
for (int j = 0; j <= ky; ++j) {
ret.sum[i][j] = lhs.sum[i][j];
}
}
for (int i = 0; i <= kx; ++i) {
for (int j = 0; i + j <= kx; ++j) {
for (int k = 0; k <= ky; ++k) {
for (int l = 0; k + l <= ky; ++l) {
add(ret.val[i + j][k + l], (ll)lhs.val[i][k] * rhs.val[j][l] % mod *
bnm[i + j][i] % mod *
bnm[k + l][k] % mod);
add(ret.sum[i + j][k + l], (ll)lhs.val[i][k] * rhs.sum[j][l] % mod *
bnm[i + j][i] % mod *
bnm[k + l][k] % mod);
}
}
}
}
return ret;
}
void mian() {
cin >> n >> a >> c >> b >> kx >> ky;
node U, R;
for (int i = 0; i <= kx; ++i) {
for (int j = 0; j <= ky; ++j) {
U.val[i][j] = !i;
U.sum[i][j] = 0;
R.val[i][j] = !j;
R.sum[i][j] = !j;
}
}
int ans = (ll)qpow(0, kx) * qpow(c / b % mod, ky) % mod;
add(ans, euclid::euclid<node>(a, b, c, n, U, R).sum[kx][ky]);
cout << ans << '\n';
}
bool Med;
int main() {
// debug("Mem: %.4lfMB.", fabs(&Med - &Mbe) / 1048576);
cin.tie(0)->sync_with_stdio(0);
int cas;
cin >> cas;
for (int i = 0; i < K; ++i) {
bnm[i][0] = bnm[i][i] = 1;
for (int j = 1; j < i; ++j) add(bnm[i][j] = bnm[i - 1][j - 1], bnm[i - 1][j]);
}
while (cas--) mian();
return 0;
}
/*
g++ -std=c++14 -O2 -o qoj-273 qoj-273.cpp -Wall -Wextra
-Wshadow -fsanitize=address,undefined -g
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 16ms
memory: 3980kb
input:
1000 846930887 681692778 714636916 89384 0 1 424238336 719885387 649760493 47794 0 1 189641422 25202363 350490028 16650 0 1 102520060 44897764 967513927 68691 0 1 540383427 304089173 303455737 80541 0 1 521595369 294702568 726956430 5212 0 1 861021531 278722863 233665124 65783 0 1 468703136 10151393...
output:
787440837 603410377 723035859 327613252 213481743 197744321 183595532 306097937 945612263 462240557 878873337 913033603 276973800 137776104 471637127 36869524 59950373 599468074 662996688 39221965 159523453 603757410 863747292 125209174 321695224 581226543 502962761 546511215 492741651 881346590 834...
result:
ok 1000 numbers
Test #2:
score: 10
Accepted
time: 16ms
memory: 3680kb
input:
1000 846930887 681692778 714636916 89384 0 1 424238336 719885387 649760493 47794 0 1 189641422 25202363 350490028 16650 0 1 102520060 44897764 967513927 68691 0 1 540383427 304089173 303455737 80541 0 1 521595369 294702568 726956430 5212 0 1 861021531 278722863 233665124 65783 0 1 468703136 10151393...
output:
787440837 603410377 723035859 327613252 213481743 197744321 183595532 306097937 945612263 462240557 878873337 913033603 276973800 137776104 471637127 36869524 59950373 599468074 662996688 39221965 159523453 603757410 863747292 125209174 321695224 581226543 502962761 546511215 492741651 881346590 834...
result:
ok 1000 numbers
Test #3:
score: 10
Accepted
time: 13ms
memory: 3652kb
input:
1000 846930887 681692778 714636916 89384 1 0 649760493 596516650 189641422 85387 0 1 102520060 44897764 967513927 68691 0 0 303455737 35005212 521595369 89173 1 0 861021531 278722863 233665124 65783 1 0 801979803 315634023 635723059 13930 1 0 89018457 628175012 656478043 61394 1 0 914544920 60841378...
output:
590247101 607294734 102520061 988535616 258549494 359848706 860104659 914544921 806512744 219134560 36869524 54386320 1100547 760313752 603757410 510232691 82579690 843146721 36876088 935671592 290199337 365292116 534011850 126900199 669344073 690573152 719144156 644864030 602224207 100895714 452066...
result:
ok 1000 numbers
Test #4:
score: 10
Accepted
time: 12ms
memory: 3916kb
input:
1000 846930887 681692778 714636916 89384 1 0 649760493 596516650 189641422 85387 0 1 102520060 44897764 967513927 68691 0 0 303455737 35005212 521595369 89173 1 0 861021531 278722863 233665124 65783 1 0 801979803 315634023 635723059 13930 1 0 89018457 628175012 656478043 61394 1 0 914544920 60841378...
output:
590247101 607294734 102520061 988535616 258549494 359848706 860104659 914544921 806512744 219134560 36869524 54386320 1100547 760313752 603757410 510232691 82579690 843146721 36876088 935671592 290199337 365292116 534011850 126900199 669344073 690573152 719144156 644864030 602224207 100895714 452066...
result:
ok 1000 numbers
Test #5:
score: 10
Accepted
time: 176ms
memory: 3692kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers
Test #6:
score: 10
Accepted
time: 177ms
memory: 3720kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers
Test #7:
score: 10
Accepted
time: 175ms
memory: 3752kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers
Test #8:
score: 10
Accepted
time: 180ms
memory: 3720kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers
Test #9:
score: 10
Accepted
time: 176ms
memory: 3688kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers
Test #10:
score: 10
Accepted
time: 179ms
memory: 3688kb
input:
1000 846930887 681692778 714636916 89384 3 3 649760493 596516650 189641422 85387 2 3 102520060 44897764 967513927 68691 0 6 303455737 35005212 521595369 89173 7 0 861021531 278722863 233665124 65783 7 1 801979803 315634023 635723059 13930 9 0 89018457 628175012 656478043 61394 9 0 914544920 60841378...
output:
269986411 687117872 337796106 649269006 273534477 925890819 789776059 781917067 471414212 683680813 655243026 766680733 110386800 920667633 42177293 33248798 268698025 97602241 455950431 787378605 628127823 884695308 910301084 481441390 301149571 40678494 744524425 997602040 853435603 942399367 4371...
result:
ok 1000 numbers