1 #include <cstdlib> 2 #include <iostream> 3 using namespace std; 4 int main(int argc, char *argv[]) 5 { 6 int x, y; 7 cin >> x >> y; 8 9 int result = 1; 10 for(int i=0; i<y; i++) 11 result = result * x % 1000; 12 13 cout << result << endl; 14 15 system("PAUSE"); 16 return EXIT_SUCCESS; 17 }
当M, N很大时, M的N次方没法用基本的数据类型表示...分析能够发现, 乘积的最后三位只与乘数和被乘数的最后三位有关, 而与高位无关, 因此每次将乘积结果对1000取模便可...ios