結果
問題 |
No.167 N^M mod 10
|
ユーザー |
![]() |
提出日時 | 2015-03-20 00:10:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,323 bytes |
コンパイル時間 | 470 ms |
コンパイル使用メモリ | 55,896 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 23:30:52 |
合計ジャッジ時間 | 1,359 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:60:17: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized] 60 | cout << ans << endl; | ^~~
ソースコード
#include <iostream> #include <string> using namespace std; string N; string M; int sumFigure(int size) { int sum = 0; for (int i = 0; i < size; i++) { sum += M[i] - '0'; } return sum; } int main() { int ans; cin >> N >> M; if (M == "0") { cout << 1 << endl; return 0; } int digit = N[N.size() - 1] - '0'; int sizeM = M.size(); int sum = sumFigure(sizeM); int lastTwoDigit = M[sizeM - 1] - '0' + (M[sizeM - 2] - '0') * 10; if (digit == 0 || digit == 1 || digit == 5 || digit == 6) ans = digit; else if (digit == 4 || digit == 9) { if (sum % 2 == 0) { if (digit == 4) ans = 6; else ans = 1; } else { ans = digit; } } else if (digit == 2 || digit == 3 || digit == 7 || digit == 8 || digit == 9) { if (lastTwoDigit % 4 == 0) { if (digit == 2) ans = 6; else if (digit == 3) ans = 1; else if (digit == 7) ans = 1; else if (digit == 8) ans = 6; } else if (lastTwoDigit % 4 == 1) { ans = digit; } else if (lastTwoDigit % 4 == 2) { if (digit == 2) ans = 4; else if (digit == 3) ans = 9; else if (digit == 7) ans = 9; else if (digit == 8) ans = 4; } else if (lastTwoDigit % 4 == 3) { if (digit == 2) ans = 8; else if (digit == 3) ans = 7; else if (digit == 7) ans = 3; else if (digit == 8) ans = 2; } } cout << ans << endl; return 0; }