LightOJ1282 Leading and Trailing
题面
给定两个数n,k 求n^k的前三位和最后三位
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 < 2^31) and k (1 ≤ k ≤ 10^7).
Solution
后面一问是搞笑的
前面一问?
也是搞笑的,用double除成小于1的数算就好了
滑稽题
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
ll n, k, ansr, ansl;
IL ll Powr(RG ll x, RG ll y, RG ll MOD){
RG ll cnt = 1;
for(; y; y >>= 1, x = x * x % MOD) if(y & 1) cnt = cnt * x % MOD;
return cnt;
}
IL double Powl(RG double x, RG ll y){
while(x >= 1) x /= 10; RG double cnt = 1.0;
for(; y; y >>= 1){
if(y & 1){
cnt = cnt * x;
while(cnt < 0.1) cnt *= 10;
}
x = x * x;
while(x < 0.1) x *= 10;
}
while(cnt < 100) cnt *= 10;
return cnt;
}
int main(RG int argc, RG char *argv[]){
for(RG int T = Read(), i = 1; i <= T; ++i){
n = Read(); k = Read();
ansl = Powl(n, k); ansr = Powr(n, k, 1000);
printf("Case %d: %lld ", i, ansl);
printf("%lld%lld%lld\n", ansr / 100, (ansr % 100) / 10, ansr % 10);
}
return 0;
}
LightOJ1282 Leading and Trailing的更多相关文章
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
- LightOJ-1282 Leading and Trailing 模算数 快速幂 对数的用法
题目链接:https://cn.vjudge.net/problem/LightOJ-1282 题意 给出两个正整数n(2 ≤ n < 231), k(1 ≤ k ≤ 1e7) 计算n^k的前三 ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- 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 ...
随机推荐
- php实现粘贴截图并完成上传功能
<?php header("Access-Control-Allow-Origin:*"); $url = 'http://'.$_SERVER['HTTP_HOST']; ...
- docker 报错:x509: certificate has expired or is not yet valid
环境:centos 7 程序:docker 下载镜像报错: # docker pull centos Pulling repository centos FATA[0004] Get https:// ...
- SpringMvc笔记-对RESTFUL风格的配置
1.@RequestMapping注解可以使用如下参数: 1,params:例如params={'username',"age!=100"}表示需要usernmame并且age 属 ...
- Hibernate学习(五)lazy属性学习(true和extra区别)
Lazy(懒加载)在hibernate何处使用:1.<class>标签上,可以取值:true/false,(默认值是:true)2.<property>标签上,可以取值:tru ...
- mongodb 3.4 分片 一主 一副 一仲 鉴权集群部署.
Docker方式部署 为了避免过分冗余,并且在主节点挂了,还能顺利自动提升,所以加入仲裁节点 mongodb版本: 环境:一台虚拟机 三个configsvr 副本: 端口为 27020,27021,2 ...
- 情景linux--如何优雅地退出telnet
情景linux--在脚本中如何优雅地退出telnet 情景 telnet命令是TELNET协议的用户接口,它支持两种模式:命令模式和会话模式.虽然telnet支持许多命令,但大部分情况下,我们只是使用 ...
- 吾八哥学Selenium(二):操作输入框/按钮的方法
一个web页面一定少不了输入框或者按钮这两种元素,那么在Python里如何使用Selenium操作web页面里的输入框和按钮呢?本文带你简单入门. 本文采用了一个例子,就是利用Selenium打开百度 ...
- linux 集群及lvs
集群及LVS 集群: 一组通过高速网络互联的计算机组,并以单一系统的模式加以管理 价格很多服务器集中起来,提供同一种服务,在客户端看起来就像只有一个服务器 可以在付出较低成本的情况下获得在性能,可靠性 ...
- 面向对象的线程池Threadpool的封装
线程池是一种多线程处理形式,预先创建好一定数量的线程,将其保存于一个容器中(如vector), 处理过程中将任务添加到队列,然后从容器中取出线程后自动启动这些任务,具体实现如下. 以下是UML图,展示 ...
- Android设置View抖动动画
在应用中,有时候我们要吸引用户去点击某些按钮,比如应用市场的推荐按钮,为了能够吸引用户主动点击而且不过分的打扰用户,最好的方法就是给我们想吸引用户注意的view添加一些抖动动画,比如这张图 这里我主要 ...