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 ...
随机推荐
- 【转】UINavigationController 直接返回到第一级目录
原文网址:http://blog.csdn.net/justinjing0612/article/details/7360852 [self.navigationController popViewC ...
- pair类型 这次遇到了,记录下来,方便彼此xue习
首先,这个pair类型是在头文件utility.h中. 一个piar保存两个数据成员,是用来生成特定类型的模板,当创建一个pair时,我们必须提供两个类型名,pair的数据成员将具有对应的类型,两个类 ...
- PCB SLOT槽孔数量计算方法,同CAM350孔数一致 实现方法
最近有好几个写脚本的朋友问我,SLOT槽孔孔的如何计算的,要求孔数与CAM350孔数保持一致. 前几年通过在CAM350里面不断测试,结果是:CAM 350中SLOT槽孔,孔与孔之间最高位,凸位高度值 ...
- TPshop规格组合错误
TPshop规格组合错误 修改: admin/logic/goodslogic.class.php 中 方法:getSpecInput() 中 asort($spec_arr_sort) 去掉
- thymeleaf公共页面元素抽取
1.抽取公共片段 使用thymeleaf的th:fragment为样抽取的公共片段命名, 如下把div标签命名为 copy,就可以获取到div整个里的内容<div th:fragment=&qu ...
- ROS-TF-监听
前言:监听第一只海龟的位置,然后让第二只海龟跟随第一只海龟. 通过监听tf,我们可以避免繁琐的旋转矩阵的计算,而直接获取我们需要的相关信息. 一.新建cpp文件 新建turtle_tf_listene ...
- 2013 ACM/ICPC Asia Regional Changsha Online - J
原题戳这里. 题意: 有一未知列数a1,a2,a3.....an, 已知s[i]=a[i-1]+a[i]+a[i] (1<i<n) s[1]=a[1]+a[2]; s[n]=a[n-1] ...
- mac下配置nginx
nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,下面我们来了解下nginx的用法. 安装nginx 使用brew安装nginx brew install ...
- Spring Boot (15) pom.xml设置
继承spring-boot-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时制定其版本 <paren ...
- 自学Python五 爬虫基础练习之SmartQQ协议
BAT站在中国互联网的顶端,引导着中国互联网的发展走向...既受到了多数程序员的关注,也在被我们所惦记着... 关于SmartQQ的协议来自HexBlog,根据他的博客我自己也一步一步的去分析,去尝试 ...