方法二#include <bits/stdc++.h>#define ll long longusing namespace std;int qpow(int a, int k, int P) {int ans = 1;while (k) {if (k & 1) ans = 1LL * ans * a % P;k >>= 1;a = 1LL * a * a % P;}return ans;}bool solve() {int a, b, d;cin >> a >> b >> d;int k = __builtin_ctz(d);if (k > __builtin_ctz(a) || k > __builtin_ctz(b)) return false;d >>= k;ll x = (qpow((d + 1) / 2, 30 - k, d) - 1 + d) % d * (1LL << 30) + (1 << 30) - (1 << k);cout << x << '\n';return true;}int main() {std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin >> t;while (t--) {if (!solve()) cout << -1 << '\n';}return 0;}
推荐阅读
- Div. 2 Codeforces Round #832 A~C题解
- Div. 1 + Div. 2, Rated, Prizes! CodeTON Round 3 A-D
- C.差分维护,D.容斥原理 CodeTON Round 3
- Div. 2 Codeforces Round #832 A-D
- Div. 3 Codeforces Round #820 A-G
- Codeforces 1670 E. Hemose on the Tree
- Div. 1 + Div. 2 Codeforces Round #831 A-E
- Codeforces Global Round 23 A-D
- Div. 4 Codeforces Round #827 A-G
- Div. 3 Codeforces Round #826 A-E