HDU 1061 rightmost Digit

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=1061

Rightmost digitdescription

Given a positive integer N, you should output the most right digit of n^n.

Input

The input contains several test cases. The first line of the input was a single integer T which is the number of test cases. T test Cases follow.
Each test case is contains a single positive integer N (1<=n<=1,000,000,000).

Output

For each test case, you should output the rightmost digit of n^n.

Sample Input

3
3
5

Sample Output

7
5

Fast power:

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < cstdio> #include <vector> #include <map>using std::map;using std::min;using std::find;using std::p air; Using std::vector;using std::multimap; #define PB (E) push_back (e) #define SZ (c) (int) (c). Size () #define MP (A, b) make_pair (A, B) #define ALL (c) (c). Begin (), (c). End () #define ITER (c) __typeof ((c). Begin ()) #define CLS (arr, Val) memset (arr, Val, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int N = 100001;const int INF = 0x3f3f3f3f;typedef Unsig    Ned Long Long ull;ull pow_mod (int n) {ull ans = 1, x = n;        while (n) {if (n & 1) ans = ans * x% 10;        x = x * x% 10;    n >>= 1; } return ans;    int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w+", stdout); #endif int t, n;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);    printf ("%lld\n", Pow_mod (n)); } return 0;}

Hdu 1061 rightmost Digit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.