結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2017-07-07 21:48:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,412 bytes |
| コンパイル時間 | 119 ms |
| コンパイル使用メモリ | 23,552 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-22 01:42:34 |
| 合計ジャッジ時間 | 880 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp:3:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
3 | main(){
| ^~~~
main.cpp: In function ‘int main()’:
main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%s %s",N,M);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
main(){
char N[10001];
char M[10001];
scanf("%s %s",N,M);
int iszero = 0;
if(strlen(M)==1){
M[1] = M[0];
M[0] = '0';
M[2] = '\0';
iszero = 1;
}
int base = N[strlen(N)-1] - '0';
int exp = (M[strlen(M)-2] - '0')*10 + M[strlen(M)-1] - '0';
int ans;
if(exp == 0 && iszero){
ans = 1;
}else{
if(base == 0){
ans = 0;
}
if(base == 1){
ans = 1;
}
if(base == 2){
int num[] = {6,2,4,8};
ans = num[exp%4];
}
if(base == 3){
int num[] = {1,3,9,7};
ans = num[exp%4];
}
if(base == 4){
int num[] = {6,4};
ans = num[exp%2];
}
if(base == 5){
ans = 5;
}
if(base == 6){
ans = 6;
}
if(base == 7){
int num[] = {1,7,9,3};
ans = num[exp%4];
}
if(base == 8){
int num[] = {6,8,4,2};
ans = num[exp%4];
}
if(base == 9){
int num[] = {1,9};
ans = num[exp%2];
}
}
printf("%d\n",ans);
}
/*
必要桁数:2
0乗=1
n=0 -> 常に0
n=1 -> 常に1
n=2 -> 2,4,8,6
n=3 -> 3,9,7,1
n=4 -> 4,6
n=5 -> 常に5
n=6 -> 常に6
n=7 -> 7,9,3,1
n=8 -> 8,4,2,6
n=9 -> 9,1
*/
Bantako