方法一:取模
例:求1992的n次方的末两位数字
#include<iostream>
using namespace std;
int main()
{int a=1,t=0,n;cin>>n;do{++t;a=(a*92)%100;//注意本题只能进行取模运算,因为结果数值过大必定溢出 }while(t<n);cout<<a<<endl;return 0;
}
对于这种题目,最好一开始就取模,不然在运算过程中可能就会发生数据的溢出
例:求1992的n次方的末两位数字
#include<iostream>
using namespace std;
int main()
{int a=1,t=0,n;cin>>n;do{++t;a=(a*92)%100;//注意本题只能进行取模运算,因为结果数值过大必定溢出 }while(t<n);cout<<a<<endl;return 0;
}
对于这种题目,最好一开始就取模,不然在运算过程中可能就会发生数据的溢出