Apart from the novice programmers, all others know that you can’t exactly represent numbers raised to some high power. For example, the C function pow(125456, 455) can be represented in double datatype format, but you won’t get all the digits of the result. However we can get at least some satisfaction if we could know few of the leading and trailing digits. This is the requirement of this problem.

Input

The first line of input will be an intege.T<1001, where T represents the number of test cases. Each of the next T lines contains two positive integers,n and k.n will fit in

32 bit integer and k will be less than 10000001.

Output

For each line of input there will be one line of output. It will be of the formt.LLL:::TTT, where LLL represents the first three digits of n,k and TTT represents the last three digits of n,k. You are assured that n k will contain at least 6 digits.

Sample Input

2

123456 1

123456 2

Sample Output

123...456

152...936

题目大意:两个数n、k,求n^k的前三位数字与后三位数字。

题目解析:后三位数字很容易求,通过幂取模即可。先考虑n不做幂运算时如何取前三位,令d=log10(n),则d=a(整数部分)+i(小数部分),n=10^d=10^(a+i)=10^a*10^i。

则10^i*100即为前三位。以123456为例,d=log10(123456)=5+i,则123456=10^i*10^5。又因为123456=1.23456*10^5,所以10^i=1.23456,所以前三位为10^i*100=123。

再来考虑n做幂运算时,将n^k变换为10^(klog(n)),则d=k*log10(n),接下来就不必细说了。

代码如下:

# include<iostream>
# include<cstdio>
# include<cstring>
# include<string>
# include<cmath>
# include<algorithm>
using namespace std;
int mypow(long long a,long long b)
{
if(b==0)
return 1;
if(b==1){
a%=1000;
return a;
}
long long t=mypow(a,b/2);
t*=t;
t%=1000;
if(b&1)
t*=a;
t%=1000;
return t;
}
int main()
{
int T,k,i;
long long n;
scanf("%d",&T);
while(T--)
{
cin>>n>>k;
int ans2=mypow(n,k);
double u=k*log10(n);
double ans1=pow(10,u-(int)u)*100;
printf("%d...%03d\n",(int)ans1,ans2);
}
return 0;
}

UVA-11029 Leading and Trailing的更多相关文章

  1. Uva 11029 Leading and Trailing (求n^k前3位和后3位)

    题意:给你 n 和 k ,让你求 n^k 的前三位和后三位 思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0 资料:求n^k的前m位 博客连接地址 代码: #include < ...

  2. UVA 11029 || Lightoj 1282 Leading and Trailing 数学

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...

  3. lightoj 1282 && uva 11029

    Leading and Trailing lightoj 链接:http://lightoj.com/volume_showproblem.php?problem=1282 uva 链接:http:/ ...

  4. LightOJ 1282 Leading and Trailing (快数幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Me ...

  5. 【LightOJ1282】Leading and Trailing(数论)

    [LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...

  6. Leading and Trailing (数论)

    Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...

  7. Leading and Trailing(数论/n^k的前三位)题解

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...

  8. E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。

    /** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...

  9. LightOJ1282 Leading and Trailing —— 指数转对数

    题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing    PDF (English) Statistics ...

随机推荐

  1. 利用arcgis处理遥感栅格数据,得到省平均值数据

    1.准备全国省级行政区数据,需要有省级行政区信息,如下所示: 2.生成渔网数据,操作完成会生成一个面数据和一个点数据,我们主要用点数据进行后面的操作. 3.提取栅格数据的值到渔网点数据中. 4.将区域 ...

  2. 关于QStandardItemModel

    类QabstractItemModel,QabstractListModel,QAbstractTableModel不保存数据,用户需要从这些类派生出子类,并在子类中定义某种数据结构来保存数据.与此不 ...

  3. 深入hibernate的三种状态(转)

    hibernate的三种状态: 瞬时对象,持久化对象,托管对象. hibernate的两级缓存:1>一级缓存:session    2>二级缓存:sessionfactory. 瞬时对象: ...

  4. win7 安装.Net framework 4.0出现 安装不成功,错误代码0x80240037 的解决方法

    1.安装说明 系统:win7 64位 安装包:dotNetFx40_Full_x86_x64.exe(.Net framework 4.0) 出现的问题:在win7 上安装dotNetFx40_Ful ...

  5. P3627 [APIO2009]抢掠计划

    P3627 [APIO2009]抢掠计划 Tarjan缩点+最短(最长)路 显然的缩点...... 在缩点时,顺便维护每个强连通分量的总权值 缩完点按照惯例建个新图 然后跑一遍spfa最长路,枚举每个 ...

  6. Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

    Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte 一.问题 request.Reque ...

  7. MQ内存消耗与积压分析

    [root@iZ23nn1p4mjZ logs]# rabbitmqctl status Status of node rabbit@iZ23nn1p4mjZ ... [{pid,15425}, {r ...

  8. 20145105 《Java程序设计》第7周学习总结

    20145105 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 一.认识时间与日期 (一)时间的度量 格林威治标准时间 世界时 国际原子时 世界协调时 Uni ...

  9. 20145105 《Java程序设计》第6周学习总结

    20145105 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 一.InputStream与OutputStream (一)串流设计的概念 输入串流代表对象:j ...

  10. 20165310 Java实验四 《Android程序设计》

    20165310 实验四 <Android程序设计> 第24章:初识Android 任务一:改写res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号 首 ...