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; }
原文地址:http://blog.csdn.net/qq_16255321/article/details/39022315