HDU 1061-Rightmost Digit(高速幂)
HDU 高速 Digit
2023-09-27 14:25:13 时间
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32258 Accepted Submission(s): 12403
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 is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Each test case 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 4O(logn)的复杂度就是快QAQ题意 :求n^n%10 n<1000000000#include <iostream> #include <cstring> #include <cstdio> #include <cctype> #include <cstdlib> #include <algorithm> #include <set> #include <vector> #include <string> #include <map> #include <queue> using namespace std; #define LL long long LL multimod(LL a,LL n,LL m) { LL ans=1,tem=a; while(n) { if(n&1) ans=ans*tem%m; tem=tem*tem%m; n/=2; } return ans; } int main() { LL a,b;int T; cin>>T; while(T--) { cin>>a; cout<<multimod(a,a,10)<<endl; } return 0; }
相关文章
- hdu 4309 最大流 + DFS
- HDU 5299 Circles Game
- 2015 Multi-University Training Contest 4 hdu 5335 Walk Out
- HDU 1255 覆盖的面积
- HDU 3001 Travelling
- HDU 1596 find the safest road
- HDU 5512 Pagodas (数论)
- 【HDU - 4341】Gold miner(分组背包)
- 组合数学第一发 hdu 2451 Simple Addition Expression
- HDU 4950 Monster(公式)
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
- hdu 1754 I Hate It (线段树、单点更新)(PS:ios::sync_with_stdio(false)可以加快cin、cout的读取写出速度)