I
unknown
c_cpp
10 months ago
1.1 kB
5
Indexable
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define UwU cin.tie(0)->sync_with_stdio(0)
#define nl '\n'
#define REP(n) for (auto _ = (n); _--;)
#define FOR(i, init, n) for (int64_t i = (init), __ = (n); i < __; i++)
#define ROF(i, init, n) for (int64_t i = (init), ___ = (n); i >= ___; i--)
const int64_t mod = 1e9 + 7;
int64_t a, b, c, x, y;
int64_t ar[2][2];
int64_t recur(int64_t x, int64_t y) {
if (x < 2 && y < 2) return ar[x][y];
int64_t m = (x > y ? x : y) + 1;
int64_t i;
for (i = 0; (1<<i) < m; i++)
;
i /= 2;
cout << "i = " << i << nl;
cout << "x = " << x << nl;
cout << "y = " << y << nl;
if (x >= i) {
if (y >= i)
return (recur(x%i, y%i) * c) % mod;
return (recur(x%i, y%i) * b) % mod;
}
if (y >= i)
return (recur(x%i, y%i) * a) % mod;
return recur(x%i, y%i) % mod;
}
void solve() {
cin >> a >> b >> c >> x >> y;
ar[0][0] = 1;
ar[0][1] = a;
ar[1][0] = b;
ar[1][1] = c;
cout << recur(x, y) << nl;
}
int main() {
UwU;
int ts = 1;
cin >> ts;
for (; ts--;) {
solve();
}
}
Editor is loading...
Leave a Comment