Submission #691257


Source Code Expand

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

namespace math { namespace integer {

template<class value_type> value_type mod_mul(value_type x, value_type k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
template<class value_type> value_type mod_pow(value_type x, value_type n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class value_type> value_type extgcd(value_type a, value_type b, value_type& x, value_type& y) { value_type d = a; if(b != 0) { d = extgcd(b, a%b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class value_type> value_type mod_inverse(value_type x, ll mod) { return mod_pow(x, value_type(mod-2), mod); /* use fermat */ }
template<class value_type> value_type mod_inverse_composite_num_mod(value_type a, ll mod) { value_type x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

int main() {

  ll n, m, p; cin >> n >> m >> p;
  cout << mod_pow(n, p, m) << endl;
  
  return 0;
}

Submission Info

Submission Time
Task B - n^p mod m
User motxx
Language C++14 (Clang 3.8.0)
Score 100
Code Size 2112 Byte
Status AC
Exec Time 13 ms
Memory 888 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status AC
AC × 27
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 13 ms 888 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 5 ms 256 KB
009.txt AC 5 ms 256 KB
010.txt AC 4 ms 256 KB
011.txt AC 5 ms 256 KB
012.txt AC 5 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