結果
| 問題 | No.3522 冪乗乗 |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-02-09 17:28:21 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 4,126 bytes |
| 記録 | |
| コンパイル時間 | 8,778 ms |
| コンパイル使用メモリ | 532,068 KB |
| 実行使用メモリ | 30,064 KB |
| 平均クエリ数 | 30.90 |
| 最終ジャッジ日時 | 2026-05-01 21:00:31 |
| 合計ジャッジ時間 | 13,761 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 63 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template <int m> istream& operator>>(istream& is, static_modint<m>& a) {long long x; is >> x; a = x; return is;}
template <int m> istream& operator>>(istream& is, dynamic_modint<m>& a) {long long x; is >> x; a = x; return is;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}
// Start 14:59
// Fermat's little theorem and Euler's theorem
//(I) N = 0 mod B
// M^L = 0 (M = 0 and L > 0)
// M^L != 0 (M != 0 or(M = 0 and L = 0))
// N^(M^L) = 1 (M = 0 and L > 0)
// N^(M^L) = 0 (M != 0 or(M = 0 and L = 0))
//(II) B = 1
// ans = 1
//(III) otherwise
// a^(phi(B)) = 1 mod(B)
// a^(phi(phi(B))) = 1 mod(phi(B))
// Start Implementation 15:15
// 15:41 Submission -> WA
// int -> long long
// 15:41 Submission -> WA
// Euler's theorem is ng! a and B are now always coprime!!
// regularity?
// a_i = n^i mod B
// at most B-length repetition
// the length L is always divides B-1 ? <- False
// B = _Prod p_i e_i
// CRT? <- ( ; ; )
// the length L is always divides phi(B) ? <- ?
// 16:22 break
// 16:50 Restart
// multiprecision
// simply calculate N^(M^L) O(log(M^L)) = O(L log M)
// 16:59 Submission -> WA
// corner??
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
template<typename T>
T pow_mod(T A, T N, T MOD){
T res = 1 % MOD;
A %= MOD;
while(N){
if(N & 1) res = (res * A) % MOD;
A = (A * A) % MOD;
N >>= 1;
}
return res;
}
template<typename T>
T pow_simple(T A, T N){
T res = 1;
while(N){
if(N & 1) res = (res * A);
A = (A * A);
N >>= 1;
}
return res;
}
int main(){
int n, m, l;
cin >> n >> m >> l;
int b = -1;
{
// ok >= b, ng < b
int ok = 1000000001, ng = 0;
while(ok - ng > 1){
int mid = (ok + ng) / 2;
cout << "? " << mid << ' ' << 1 << "\n";
flush(cout);
int res;
cin >> res;
if(res < mid) ok = mid;
else ng = mid;
}
b = ok;
}
if(b == 1){
cout << "! 0\n";
return 0;
}
n %= b;
if(n == 0){
if(m == 0 and l > 0) cout << "! 1\n";
else cout << "! 0\n";
return 0;
}
Bint e = pow_simple<Bint>(m, l);
Bint ans = pow_mod<Bint>(n, e, b);
cout << "! " << ans << "\n";
return 0;
}