Leading and Trailing (数论)
Leading and Trailing
https://vjudge.net/contest/288520#problem/E
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
求前三位则需要一些数学知识对于给定的一个数n,它可以写成10^a,其中这个a为浮点数,则n^k=(10^a)^k=10^a*k=(10^x)*(10^y);其中x,y分别是a*k的整数部分和小数部分,对于t=n^k这个数,它的位数由(10^x)决定,它的位数上的值则有(10^y)决定,因此我们要求t的前三位,只需要将10^y求出,在乘以100,就得到了它的前三位。
fmod(x,1)可以求出x的小数部分。
参考博客:https://blog.csdn.net/w144215160044/article/details/48916839
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int pow_mul(ll a,ll b){
int ans=;
while(b){
if(b&) ans=ans*a%;
b>>=;
a=a*a%;
}
return ans;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
// std::ios::sync_with_stdio(false);
int t;
cin>>t;
for(int _=;_<=t;_++){
ll n,k;
cin>>n>>k;
int ans1=pow(10.0,2.0+fmod(k*log10(n*1.0),));
int ans2=pow_mul(n,k);
printf("Case %d: %d %03d\n",_,ans1,ans2);
} }
Leading and Trailing (数论)的更多相关文章
- LightOJ 1282 Leading and Trailing 数论
题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x* ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- 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} ...
随机推荐
- 选择、操作web元素
11月1日 什么是web元素 Selenium自动化主要就是:选择界面元素,操作界面元素(输入操作:点击.输入文字.拖拽等,输出操作:获取元素的各种属性),根据界面上获取的数据进行分析和处理 选择元素 ...
- unrecognized import path "golang.org/x/net/html"
go run的时候报:unrecognized import path "golang.org/x/net/html" 应该是被墙掉了,自己去github上下载包即可 git cl ...
- delphi 属性 参数 新注释
delphi 属性 参数 新注释,在写代码的时候,可以自动看到属性.参数的的备注说明,太方便了. Tmyclass=class /// <summary> /// 姓名 /// </ ...
- 函数参数,const 引用 和 非 const引用是不同的函数。
举个例子, void f(const int &x) 和 void f(int &x) 是不同的函数. 函数的返回值不能作为区分
- linux 常用命令记录&& xsheel 使用记录
cp -r x1 x2 复制文件x1到x2 ls 当前目录下的文件列表 ll ...
- 分布式存储Seaweedfs源码分析
基于源码版本号 0.67 , [Seaweedfs以前旧版叫Weedfs]. Seaweedfs 是一个非常优秀的由 golang 开发的分布式存储开源项目, 虽然在我刚开始关注的时候它在 githu ...
- 灵活控制 Hibernate 的日志或 SQL 输出,以便于诊断
我们在使用 Hibernate 时一般只会关注是否显示生成的 SQL 语句,不过有些时候还不够.默认时 Hibernate 执行的 SQL 语句是打印在控制台上的,它也可以配置为输出给 Log4J 或 ...
- jenkins+docker+docker-compose完整发版流程
首先搭建jenkins+maven+nexus这一套自动化打包工具,并配置好相应配置,这里就不再赘述了. 其次,搭建好docker集群和私有仓库,以及安装好docker-compose工具,配置好相应 ...
- openwrt中防暴力破解shell的脚本
原文:http://www.right.com.cn/forum/thread-124429-1-1.html 原理:1. snort做入侵检测是很好,但是太大太复杂,我们需要轻量化的操作.当对方进行 ...
- 讲一讲Servlet的生命周期
1 实例化 servlet 容器创建servlet的实例; 2初始化 该容器调用init()方法; 每个实例,init()方法只被调用一次 3 服务 如果请求Servlet,则容器 ...