您的位置:首页 > 大数据 > 人工智能

lightoj Leading and Trailing

2016-08-23 19:59 375 查看
 Leading and Trailing



 
  

PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB
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.

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing two integers: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107).

Output

For each case, print the case number and the three leading digits (most significant) and three trailing digits (least significant). You can assume that the input is given such that nk contains at least six digits.

Sample Input

Output for Sample Input

5

123456 1

123456 2

2 31

2 32

29 8751919

Case 1: 123 456

Case 2: 152 936

Case 3: 214 648

Case 4: 429 296

Case 5: 665 669

#include<stdio.h>

#include<string.h>

#include<math.h>

typedef long long LL;

LL powermod(LL a,LL b,LL c)

{
LL ans=1;
a=a%c;
while(b>0)
{
if(b%2)
ans=ans*a%c;
b/=2;
a=a*a%c;
}
return ans;

}

int main()

{
int t,l;

    LL n,k;

    l=1;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&n,&k);
LL a=powermod(n,k,1000);
   double s=1.0*k*log10(n*1.0);
   double b=pow(10,s-int(s));
   LL su=LL(100*b);
printf("Case %d: %lld %03lld\n",l++,su,a);
}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: