水题
末位取模快速幂
首位取对数瞎搞
题目链接
http://lightoj.com/volume_showproblem.php?problem=1282
#include <stdio.h>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL mod=1000;
LL fmod(LL a,LL b){
LL ans=1;
if(a==0)return 0;
while(b){
if(b&1){
ans*=a;
ans%=mod;
}
a*=a;
a%=mod;
b>>=1;
}
return ans;
}
int main(void)
{
int t,cas=0;
scanf("%d",&t);
while(t--){
LL n,p;
scanf("%lld%lld",&n,&p);
printf("Case %d: ",++cas);
double ans=p*log10((double)n);
ans=ans-floor(ans);
ans=pow(10,ans);
while(ans<100){
ans*=10;
}
printf("%d ",(int)ans);
LL ans1=fmod(n%1000,p);
printf("%03d\n",ans1);
}
return 0;
}

本文介绍了一种结合快速幂运算与取模运算的算法实现方式,并通过具体实例展示了如何利用对数运算和快速幂来解决特定类型的问题。该方法首先采用对数运算获取数值的有效位数,然后使用快速幂进行模运算,最后输出计算结果。
5294

被折叠的 条评论
为什么被折叠?



