链接:

https://vjudge.net/problem/LightOJ-1282

题意:

You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.

思路:

后三位快速幂取余,考虑前三位。

\(n^k\)可以表示为\(a*10^m\)即使用科学计数法。

对两边取对数得到\(k*log10(n) = log10(a)+m\)

则x = log10(a)是k*log10(n)的小数部分。

a = pow(10, x).就是科学计数法的前面部分。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map> using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e6+10;
const int MOD = 1e9+7; LL n, k; LL PowMod(LL a, LL b)
{
LL res = 1;
while(b)
{
if (b&1)
res = res*a%1000;
a = a*a%1000;
b >>= 1;
}
return res;
} int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%lld%lld", &n, &k);
double v = 1.0*k*log10(n);
v -= (LL)v;
LL r1 = (LL)(pow(10, v)*100);
LL r2 = PowMod(n, k);
printf(" %lld %03lld\n", r1, r2);
} return 0;
}

最新文章

  1. Linux 内存管理
  2. MySQL Cursor
  3. WebMatrix之WebMatrix.Data
  4. Android 转载一篇.9图片详解文章
  5. Web Service 性能测试工具比较
  6. 使用Gson解析复杂的json数据
  7. delete archivelog all 无法彻底删除归档日志?
  8. socket编程发送GET请求
  9. Web.xml配置详解之context-param(转)
  10. 在eclipse中创建web项目
  11. Linux服务器挂死案例分析
  12. sublime前端开发工具常用技巧
  13. Spring配置属性文件
  14. 【游戏开发】Excel表格批量转换成CSV的小工具
  15. C#面向对象方式设置、读取应用配置
  16. 一篇不一样的docker原理解析
  17. 小程序 -- ui布局
  18. Linux LB--负载均衡和高可靠
  19. Trapping Rain Water LT42
  20. 老李的blog使用日记(2)

热门文章

  1. [转帖]WannaCry惊天大发现!疑似朝鲜黑客组织Lazarus所为
  2. Fiddler如何监听PC和手机
  3. spring boot 初始
  4. 【C++札记】指针数组和数组指针
  5. Django连接多个数据库并实现读写分离
  6. array_walk、array_map、array_filter 的用法
  7. 《Docker Deep Dive》Note - 纵观 Docker
  8. springboot 配置elasticsearch Java High Rest Client
  9. vue+element+upload实现头像上传
  10. [SOJ #538]好数 [CC]FAVNUM(2019-8-6考试)