题意:a^b次方,让你取低三位和高三位。
思路:低三位用快速模幂,高三位可以取对数。
代码如下:
1 /************************************************** 2 * Author : xiaohao Z 3 * Blog : http://www.cnblogs.com/shu-xiaohao/ 4 * Last modified : 2014-03-28 22:01 5 * Filename : uva_11029.cpp 6 * Description : 7 * ************************************************/ 8 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 #include <cstdlib> 13 #include <cmath> 14 #include <algorithm> 15 #include <queue> 16 #include <stack> 17 #include <vector> 18 #include <set> 19 #include <map> 20 #define MP(a, b) make_pair(a, b) 21 #define PB(a) push_back(a) 22 23 using namespace std; 24 typedef long long ll; 25 typedef pair<int, int> pii; 26 typedef pair<unsigned int,unsigned int> puu; 27 typedef pair<int, double> pid; 28 typedef pair<ll, int> pli; 29 typedef pair<int, ll> pil; 30 31 const int INF = 0x3f3f3f3f; 32 const double eps = 1E-6; 33 ll ta, tb; 34 35 ll a_b_MOD_c(ll a, ll b, ll c) 36 { 37 if(b==1) return a%c; 38 ll temp = a_b_MOD_c(a, b/2, c); 39 if(b%2 == 1) return (temp*temp*a)%c; 40 else return (temp*temp)%c; 41 } 42 43 int main() 44 { 45 // freopen("in.txt", "r", stdin); 46 47 int T; 48 cin >> T; 49 while(T--){ 50 cin >> ta >> tb; 51 double ansa = 100*pow(10, fmod(tb*log10(ta), 1)); 52 cout << (int)ansa; 53 int ansb = a_b_MOD_c(ta, tb, 1000); 54 printf("...%03d\n", ansb); 55 } 56 return 0; 57 }
原文:http://www.cnblogs.com/shu-xiaohao/p/3631922.html