1004 N^n's bottom number title Source: Author IGNATIUS.L (Hdu 1061) Base time limit: 1 second space limit: 131072 KB Score: 5 Difficulty: 1-level algorithm topic collection Attention Description
Gives an integer n, the last digit of the decimal representation of the output n^n (n of the n-th square).
Input
A number n (1 <= n <= 10^9)
Output
The lowest digit of the output n^n
Input example
13
Output example
3
Exercises
This problem can be done with a quick power modulo. The code is as follows:
#include <cstdio>#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <map>#include <set>#include <queue>#include <utility>#define ll long long#define ull_ unsigned long longusing namespace std ;ll quick_pow( ll a , ll b ){ ll base = a , ans = 1 % 10 ; while ( b ){ if ( b & 1 ){ ans = (ans % 10 * base % 10) % 10 ; } base = base * base % 10 ; b >>= 1 ; } return ans ;}int main(){ int n ; cin >> n ; cout << quick_pow(n , n) << endl ; return 0 ;}
51Nod 1004 N^n of the lowest number