码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ 1282

时间:2015-04-21 22:24:17      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

Status

Description

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

5

123456 1

123456 2

2 31

2 32

29 8751919

Sample Output

Case 1: 123 456

Case 2: 152 936

Case 3: 214 648

Case 4: 429 296

Case 5: 665 669

Source

Problem Setter: Shamim Hafiz
Special Thanks: Jane Alam Jan (Solution, Dataset)
/**
          题意:求a的b次幂,结果的高三位和低三位是什么
          做法:快速幂 
**/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#define mod 1000
using namespace std;
int quickpow(int n, int k)
{
    int res = 1;
    int base = n%mod;
    while(k)
    {
        if(k&1)
            res *= base;
        base *= base;
        res %= mod;
        base %= mod;
        k >>= 1;
    }
    return res;
}
int solve(int   a,int   b)
{
          double s = b*log10((double)a) - (int)(b*log10((double)a));
    s = pow(10.0,s);
    return s*100;
}
int main()
{
#ifndef ONLINE_JUDGE
         freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
          int Case = 1;
          int T;
          scanf("%d",&T);
          while(T--)
          {
                    int  a,b;
                    scanf("%d %d",&a,&b);
                    int  res = quickpow(a,b);
                    int cet =pow(10, 2+fmod(b *(double)log10((double)a), 1));
                   printf("Case %d: %d %03d\n",Case,cet,res);
                   Case++;
          }
          return 0;
}

 

LightOJ 1282

标签:

原文地址:http://www.cnblogs.com/chenyang920/p/4445561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!