Submission #691202
Source Code Expand
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
namespace solver {
#define GET_MACRO(a, b, c, d, NAME, ...) NAME
#define REP1(n) REP2(i_, n)
#define REP2(i, n) REP3(i, 0, n)
#define REP3(i, a, b) REP4(i, a, b, 1)
#define REP4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define RREP1(n) RREP2(i_, n)
#define RREP2(i, n) RREP3(i, 0, n)
#define RREP3(i, a, b) RREP4(i, a, b, 1)
#define RREP4(i, a, b, s) for (ll i = (b) - 1; i >= (ll)(a); i -= (ll)(s))
#define rep(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define each(x, c) for (auto &&x : c)
#define all(c) std::begin(c), std::end(c)
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
template<typename T>
using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using MaxPQ = priority_queue<T, vector<T>, less<T>>;
template<bool cond, typename T = void>
using enable_if_t = typename enable_if<cond, T>::type;
const int INF = 1e9 + 10;
const ll INF_LL = 1e18 + 10;
const double INF_D = 1e12;
const ld INF_LD = 1e24;
const ld EPS = 1e-8;
const ld PI = acos(-1.0l);
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, -1, 0, 1, -1, -1, 1, 1};
template<typename T>
inline T sq(const T &x){ return x * x; }
template<typename T, typename U>
inline T &chmin(T &x, const U &y){ if (x > y) x = y; return x; }
template<typename T, typename U>
inline T &chmax(T &x, const U &y){ if (x < y) x = y; return x; }
ll gcd(ll a, ll b){ return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b){ return a / gcd(a, b) * b; }
tuple<ll, ll, ll> extgcd(ll a, ll b){
if (b == 0) return make_tuple(a, 1, 0);
ll g, x, y;
tie(g, x, y) = extgcd(b, a % b);
return make_tuple(g, y, x - a / b * y);
}
ll invmod(ll a, ll m = 1000000007){
ll g, x;
tie(g, x, ignore) = extgcd(a, m);
return g == 1 ? (x + m) % m : 0;
}
void solve();
}
signed main(){
auto begin = std::chrono::high_resolution_clock::now();
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(12);
solver::solve();
auto end = std::chrono::high_resolution_clock::now();
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
#ifdef DEBUG
std::cerr << "time: " << time.count() << " [ms]" << std::endl;
#endif
}
namespace solver {
/* }}} */
void solve(){
ll n, m, p;
cin >> n >> m >> p;
ll r = 1;
while (p){
if (p & 1) r = r * n % m;
n = n * n % m;
p >>= 1;
}
cout << r << endl;
}
} /* namespace solver */
Submission Info
Submission Time |
|
Task |
B - n^p mod m |
User |
jin_matakich |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2740 Byte |
Status |
AC |
Exec Time |
4 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
AC
|
|
Set Name |
Test Cases |
Sample |
|
All |
001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt |
Case Name |
Status |
Exec Time |
Memory |
001.txt |
AC |
4 ms |
256 KB |
002.txt |
AC |
4 ms |
256 KB |
003.txt |
AC |
4 ms |
256 KB |
004.txt |
AC |
4 ms |
256 KB |
005.txt |
AC |
4 ms |
256 KB |
006.txt |
AC |
4 ms |
256 KB |
007.txt |
AC |
4 ms |
256 KB |
008.txt |
AC |
4 ms |
256 KB |
009.txt |
AC |
4 ms |
256 KB |
010.txt |
AC |
4 ms |
256 KB |
011.txt |
AC |
4 ms |
256 KB |
012.txt |
AC |
4 ms |
256 KB |
013.txt |
AC |
4 ms |
256 KB |
014.txt |
AC |
4 ms |
256 KB |
015.txt |
AC |
4 ms |
256 KB |
016.txt |
AC |
4 ms |
256 KB |
017.txt |
AC |
4 ms |
256 KB |
018.txt |
AC |
4 ms |
256 KB |
019.txt |
AC |
4 ms |
256 KB |
020.txt |
AC |
4 ms |
256 KB |
021.txt |
AC |
4 ms |
256 KB |
022.txt |
AC |
4 ms |
256 KB |
023.txt |
AC |
4 ms |
256 KB |
024.txt |
AC |
4 ms |
256 KB |
025.txt |
AC |
4 ms |
256 KB |
026.txt |
AC |
4 ms |
256 KB |
027.txt |
AC |
4 ms |
256 KB |
sample_01.txt |
AC |
4 ms |
256 KB |
sample_02.txt |
AC |
4 ms |
256 KB |