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#实现对数据库的备份还原 ( 用SQL语句实现对数据库备份还原操作 备份SqlServer数据库: backup database 数据库名 to disk (备份文件存放路径+文件名).bak 还 ...
- [CTSC 2008] 祭祀
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1143 [算法] 答案为最小路径可重复点覆盖所包含的路径数,将原图G进行弗洛伊德传递闭 ...
- bzoj 2252 [ 2010 Beijing wc ] 矩阵距离 —— 多源bfs
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2252 又没能自己想出来... 一直在想如何从每个1开始广搜更新答案,再剪剪枝,什么遇到1就不 ...
- Java 解析Json数据
Json格式字符串{success:0,errorMsg:"错误消息",data:{total:"总记录数",rows:[{id:"任务ID" ...
- [Apple开发者帐户帮助]六、配置应用服务(2)创建DeviceCheck私钥
要验证与DeviceCheck服务的通信,您将使用启用了DeviceCheck的私钥. 首先创建并下载启用了DeviceCheck 的私钥.然后获取密钥标识符(kid)以创建JSON Web令牌(JW ...
- JQuery+Bootstrap总结
================JQuery=========== JQuery 1. jQuery是什么? 一个js插件, 相比较原生的DOM操作更简单.开发效率更高 2. jQuery使用 1. ...
- jvm堆外直接内存实现高性能接入层
jvm堆外直接内存实现高性能接入层https://blog.csdn.net/phil_code/article/details/69056086
- 上传预览图片的插件jquery-fileupload
上传预览图片的插件jquery-fileupload github地址:https://github.com/blueimp/jQuery-File-Upload 中文文档:http://www.jq ...
- javascript基础(完整)
一.什么是javascript? 是一种基于对象和事件驱动(以事件驱动的方式直接对客户端的输入做出响应,无需经过服务器端)并具有安全性能的解释型脚本语言,在web应用中得到非常广泛地应用.它不需要编译 ...
- 去除DialogFragment的背景阴影,背景色,标题栏
style中: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <s ...