SPOJ - The last digit
https://vjudge.net/problem/SPOJ-LASTDIG
求最后一位,%10就完了
这个题居然要求代码小于等于700B
#include <iostream> #include <cstdio> #define p(a) putchar(a) #define For(i,a,b) for(long long i=a;i<=b;++i) using namespace std; long long T,n,x,y; long long ksm(long long a,long long b){ long long r=1; while(b>0){ if(b&1) r=r*a%10; a=a*a%10; b>>=1; } return r; } int main(){ cin>>T; while(T--){ cin>>x>>y; cout<<ksm(x,y);p('\n'); } return 0; }