Rightmost Digit Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total submission (s): 43732 Accepted Submission (s): 16434 Problem Description 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 2 3 4 Sample Output 7 6 Hint In the first case, 3 * 3 * 3 = rightmost, so the-the-digit is 7. In the second case, 4 * 4 * 4 * 4 = at the very rightmost digit is 6.
Author Ignatius.l |
1 //4 for Cycles2#include <iostream>3#include <cstdio>4 using namespacestd;5 intMain ()6 {7 Long LongN;8Cin>>N;9 Long LongT;Ten while(n--){ OneCin>>T; A intk=t%4; -t%=Ten; - if(k==2) t=t*T; the if(k==3) t=t*t*T; - if(k==0) t=t*t*t*T; -t%=Ten; -cout<<t<<Endl; + } - return 0; +}
HDU 1061 rightmost Digit (law-seeking)