Submission #691730
Source Code Expand
/*
NのP乗をMで割ったあまり
*/
#include<iostream>
#include<math.h>
using namespace std;
const unsigned long long MAX_N = 1000000000;
const unsigned long long MAX_M = 1000000000;
const unsigned long long MAX_P = 100000000000000;
unsigned long long exponentiation(unsigned long long n, unsigned long long p, unsigned long long m){
if(p == 0){
return 1;
}else if(!(p % 2)){
unsigned long long t = exponentiation(n, p/2, m);
return t * t % m;
}else{
return exponentiation(n, p-1, m) * n % m;
}
}
int main(){
unsigned long long n;
unsigned long long m;
unsigned long long p;
cin>>n>>m>>p;
unsigned long long answer = exponentiation(n, p, m);
cout<<answer<<endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - n^p mod m |
| User | hiroki6 |
| Language | C++14 (GCC 5.4.1) |
| Score | 100 |
| Code Size | 766 Byte |
| Status | AC |
| Exec Time | 6 ms |
| Memory | 256 KiB |
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 KiB |
| 002.txt | AC | 4 ms | 256 KiB |
| 003.txt | AC | 4 ms | 256 KiB |
| 004.txt | AC | 4 ms | 256 KiB |
| 005.txt | AC | 4 ms | 256 KiB |
| 006.txt | AC | 4 ms | 256 KiB |
| 007.txt | AC | 4 ms | 256 KiB |
| 008.txt | AC | 4 ms | 256 KiB |
| 009.txt | AC | 4 ms | 256 KiB |
| 010.txt | AC | 4 ms | 256 KiB |
| 011.txt | AC | 4 ms | 256 KiB |
| 012.txt | AC | 4 ms | 256 KiB |
| 013.txt | AC | 4 ms | 256 KiB |
| 014.txt | AC | 4 ms | 256 KiB |
| 015.txt | AC | 4 ms | 256 KiB |
| 016.txt | AC | 6 ms | 256 KiB |
| 017.txt | AC | 4 ms | 256 KiB |
| 018.txt | AC | 4 ms | 256 KiB |
| 019.txt | AC | 4 ms | 256 KiB |
| 020.txt | AC | 4 ms | 256 KiB |
| 021.txt | AC | 4 ms | 256 KiB |
| 022.txt | AC | 4 ms | 256 KiB |
| 023.txt | AC | 4 ms | 256 KiB |
| 024.txt | AC | 4 ms | 256 KiB |
| 025.txt | AC | 4 ms | 256 KiB |
| 026.txt | AC | 4 ms | 256 KiB |
| 027.txt | AC | 4 ms | 256 KiB |
| sample_01.txt | AC | 4 ms | 256 KiB |
| sample_02.txt | AC | 4 ms | 256 KiB |