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 ...
随机推荐
- Framebuffer 机制【转】
本文转载自:http://blog.csdn.net/paul_liao/article/details/7706477 Framebuffer Framebuffer是Linux系统为显示设备提供的 ...
- B1295 [SCOI2009]最长距离 最短路
就是一道最短路的裸题,直接跑spfa就行了.(spfa死了) 最后在答案处判断是否障碍物太多,然后就直接找最大值就行. (数据特别水,我错误算法60) 题干: Description windy有一块 ...
- awk查找特定字段
在一行中,查找字段包含exe的: ###########awk.awk######## { for(i=1;i<NF;i++) { if($i ~ /exe/) { print $i } } } ...
- [转]RDLC 动态列
本文转自:http://blog.csdn.net/luochengbang/article/details/9964551 很久没有写博客了,关于动态列,国内很少资料有介绍动态列的,所想写点心得给哥 ...
- ACM_城市交通线(简单并查集)
城市交通线 Time Limit: 2000/1000ms (Java/Others) Problem Description: A国有n座城市,编号为1~n,这n个城市之间没有任何交通线路,所以不同 ...
- EasyUI 编写实体类树状选择器
<%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/WEB-INF/ ...
- ES6 Promise(2)
Promise的兴起,是因为异步方法调用中,往往会出现回调函数一环扣一环的情况.这种情况导致了回调金字塔的出现.不仅代码写起来费劲不美观,而且问题复杂的时候,阅读代码的人也难以理解. db.save( ...
- SSIS SQL Server配置自动作业
目录: 一. 用SSMS配置作业,自助调度: 二.用SSMS调SSIS包: 一. 用SSMS配置作业,自助调度: 为验证数据,先创建一个表: CREATE TABLE test_table (id I ...
- JAVA软件工程师应该具备哪些基本素质?
必知:软件企业要求基础软件工程师具备六大基本素质,即良好的编码能力.自觉的规范意识和团队精神.认识和运用数据库的能力.较强的英语阅读和写作能力.具有软件工程的概念和求知欲和进取心. 1.良好的编码能力 ...
- react基础篇二
组件 & Props & 生命周期 组件可以将UI切分成一些独立的.可复用的部件,这样你就只需专注于构建每一个单独的部件. 组件从概念上看就像是函数,它可以接收任意的输入值(称之为“p ...