HDU 1061 N^N (n的n次方的最后一位)

it2025-09-27  94

题目意思:

http://acm.hdu.edu.cn/showproblem.php?pid=1061

求N^N的最后一位数。

题目分析:

此题有非常多种方法,主要是中循环节,看自己怎么找了。我的方法是找到全部个位数(0~9)数的循环节,详见代码。

AC代码:

/** *全部数的循环节是12 */ #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int main() { int n,t; cin>>t; while(t--){ cin>>n; cout<<(((long long) (0.5+pow((double) (n%10),n%12==0?12:n%12)))%10)<<endl; } return 0; }

转载于:https://www.cnblogs.com/bhlsheji/p/4306682.html

相关资源:数据结构—成绩单生成器
最新回复(0)