0
点赞
收藏
分享

微信扫一扫

light OJ 1282 - Leading and Trailing 数学 || double技巧

​​http://lightoj.com/volume_showproblem.php?problem=1282​​

light OJ 1282 - Leading and Trailing  数学 || double技巧_ios

light OJ 1282 - Leading and Trailing  数学 || double技巧_#include_02

light OJ 1282 - Leading and Trailing  数学 || double技巧_#define_03

light OJ 1282 - Leading and Trailing  数学 || double技巧_ios_04

light OJ 1282 - Leading and Trailing  数学 || double技巧_ios_05

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>


//int calc(LL a, LL b, int k) { //a^b的前k + 1位
// double res = b * log10(a * 1.0) - (LL)(b * log10(a * 1.0)); //小数部分
// return (int)pow(10.0, k + res);
//}
int calc(double a, LL b, int k) {
double ans = 1, base = a;
while (b) {
if (b & 1) {
ans = ans * base;
}
b >>= 1;
base = base * base;
while (ans >= 1000) ans /= 10; //保留前3位
while (base >= 1000) base /= 10;
}
return (int)ans;
}
int quick_pow(LL a, LL b, int MOD) {
LL ans = 1, base = a % MOD;
while (b) {
if (b & 1) ans = ans * base % MOD;
b >>= 1;
base = base * base % MOD;
}
return ans;
}
void work() {
LL a, b;
cin >> a >> b;
static int f = 0;
printf("Case %d: %d %03d\n", ++f, calc(a, b, 3), quick_pow(a, b, 1000));
}

int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return 0;
}

View Code

 

举报

相关推荐

0 条评论