Leading and Trailing 题解(a^b的前三位)

题目链接

题目思路

对于这种很大数还是要想到用对数

(n^k) =$10x imes10y $,其中(10^x) 的值等于位数,而(10^y)(这是一个大于等于1小于10的浮点数)决定了位数上的值。
我们把(10^y)求出来

代码

#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e6+5,inf=0x3f3f3f3f,mod=1000;
const double eps=1e-6;
ll a,b;
int tot;
ll qpow(ll a,ll b){
    ll ans=1,base=a;
    while(b){
        if(b&1) ans=ans*base%mod;
        base=base*base%mod;
        b=b>>1;
    }
    return ans;
}
signed main(){
    int _;scanf("%d",&_);
    while(_--){
        scanf("%lld %lld",&a,&b);
        double xs=b*log10(a)-(ll)(b*log10(a));
        ll ans1=(ll)(pow(10,xs)*100);
        ll ans2=qpow(a,b);
        printf("Case %d: %03lld %03lld
",++tot,ans1,ans2);
    }
    return 0;
}

不摆烂了,写题
原文地址:https://www.cnblogs.com/hunxuewangzi/p/15127455.html