#include <cmath> #include <iostream> using namespace std; //超量级幂积模运算 unsigned long superPowerMod( unsigned long c, unsigned long power, unsigned long N) { unsigned long n; __int64 result=1; for ( n=0; n<power; n++ ) { result *= c%N; if ( result > N ) { result %= N; } } return (unsigned long)result; } int main(void) { long c=123456; long power=123456789; long N=321; cout<<"正在计算中,请稍等……"<<endl; long result = superPowerMod(c,power,N); //计算123456的123456789次方的积对321取模后的结果 cout<<"结果为:"<<result<<endl; cout<<endl<<"按下回车键即可退出……"<<endl; cin.get(); return 0; }