求n^n最右边的一位
找出规律即可
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<iostream> using namespace std; int main() { int T,n,ans,t; cin>>T; while(T--) { cin>>n; t=n%10; n=(n-1)%4+1; for(ans=1;n--;ans*=t); cout<<ans%10<<endl; } return 0; }
求n^n最右边的一位
找出规律即可
#include<iostream> using namespace std; int main() { int T,n,ans,t; cin>>T; while(T--) { cin>>n; t=n%10; n=(n-1)%4+1; for(ans=1;n--;ans*=t); cout<<ans%10<<endl; } return 0; }
转载于:https://www.cnblogs.com/pcoda/archive/2012/04/30/2476808.html