結果

問題 No.167 N^M mod 10
ユーザー naimonon77
提出日時 2015-09-21 15:21:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 612 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 58,908 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-19 08:26:52
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)

typedef long long ll;
typedef unsigned long long ull;
typedef long double lb;

/* ここからが本編 */

int main(void)
{
   ll i,j,k;
   ll memory[2];
   ll n,m;
   ll tmp;
   ll ans = 0;

   cin >> n >> m;

   ans = 1;
   n %= 10;
   
   tmp = n;
   for(i=1;;i++) {
      tmp = (tmp*n)%10;
      if(tmp == n) break;
   }
   if(m % i) m %= i;
   else if(m)m = i;
   for(i=0;i<m;i++) ans = (ans*n) % 10;

   cout << ans << endl;

   return 0;
}
0