Leading and Trailing
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
后三位数字可以通过快速幂取模运算来获得,前三位数字可以通过对数的小数部分来获得!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 1000010
#define LLL 1000000000
#define INF 1000000009
LL Pow(LL x,LL k)
{
LL ret = ;
while (k)
{
if (k & !=)
ret = (ret*x)%;
x = x*x;
x %= ;
k /= ;
}
return ret;
}
int main()
{
int T;
LL n, k;
cin >> T;
for (int cas = ; cas <= T; cas++)
{
scanf("%lld%lld", &n, &k);
LL tmp = n % ;
LL ans2 = Pow(tmp, k)%,ans1;
double num = k*log10(n*1.0);
num -= LL(num);
ans1 = LL(pow(, num) * );
printf("Case %d: %lld %03lld\n", cas, ans1, ans2);
}
return ;
}
Leading and Trailing的更多相关文章
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
- Leading and Trailing (数论)
Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- UVA-11029 Leading and Trailing
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...
- E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...
- 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 ...
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
- Leading and Trailing LightOJ - 1282 题解
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31} ...
- 1282 - Leading and Trailing 求n^k的前三位和后三位。
1282 - Leading and Trailing You are given two integers: n and k, your task is to find the most signi ...
随机推荐
- c# 命令行下编译c#文件 // c# file类读写文件
c# 命令行下编译c#文件 2010-03-01 15:02:14| 分类: c# 学习|字号 订阅 在 开始 ——>程序 ——>vstool中打开vs2008命令提示. 通过 ...
- iOS开发之KVC全解
一 KVC的基本概念 1.KVC是Key Value Coding的缩写,意思是键值编码. 在iOS中,提供了一种方法通过使用属性的名称(也就是Key)来间接访问对象属性的方法,这个方法可以不通过g ...
- TPshop规格组合错误
TPshop规格组合错误 修改: admin/logic/goodslogic.class.php 中 方法:getSpecInput() 中 asort($spec_arr_sort) 去掉
- S - New Year Transportation
Problem description New Year is coming in Line World! In this world, there are n cells numbered by i ...
- ie9长度兼容
onchange="this.value=this.value.substring(0, 10)" onkeydown="this.value=this.value.su ...
- Android_方向传感器
Android方向传感器小案例,主要代码如下: package com.hb.direction; import android.app.Activity; import android.conten ...
- MYSQL 45道练习题
学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示.用S ...
- python处理中文编码
python2 读取excle中的数据时,对于汉字的读取报错: 代码:data[num][4]={"content": "测试"} data=data[num] ...
- Memcached 之缓存雪崩现象、实际案例和缓存无底洞现象
一.缓存雪崩现象 由于集群中某个memcached服务器宕机的原因,造成集群中的服务器命中率下降.只能通过访问数据库得到数据,是的数据库的压力倍增,造成数据库服务器崩溃.重启数据库还是会崩溃,但是数据 ...
- 微信jssdk图片上传
一.html页面如下: <div class="weui-cell"> <div class="weui-cell__hd"></ ...