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 ...
随机推荐
- linux下利用shell脚本实现添加crontab任务
本来直接用crontab -e 就可以打开vim,输入要执行的任务保存退出就可以添加任务直接启动运行了.但是今天组长说能不能写个shell不用打开vi就能添加到crontab的. 最先想到的是怎么在s ...
- [译]Serilog Tutorial
在过去的几年中,结构化日志已经大受欢迎.而Serilog是 .NET 中最著名的结构化日志类库 ,我们提供了这份的精简指南来帮助你快速了解并运用它. 0. 内容 设定目标 认识Serilog 事件和级 ...
- Shell 编程入门
首先创建一个文件: 在终端中输入如下命令: vi helloworld.sh 然后按i进行命令编写 下面这句话是必须写的 #!/bin/sh这句话是必须写的 #!/bin/sh a="hel ...
- c++ 回调函数使用
普通回调 #include<stdio.h> void printWelcome(int len) { printf("welcome -- %d\n", len); ...
- ubuntu17 安装中文输入法
在此说的是intelligent pinyin.我首先尝试的是搜狗输入法,虽然最终安装成功了,但还是直接卸载了.因为它不仅需要fcitx框架,在安装成功后,标题栏上面还会出现两个输入法图标.真正不能让 ...
- CentOS7上安装Nginx、PHP、MySQL
一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...
- CodeForces - 796C Bank Hacking
思路:共有n-1条边连接n个点,即形成一棵树.一开始需要选择一个点hack--将这个点视为根结点,与它相邻的点防御值加1,与它相隔一个在线点的点的防御也加1.当根节点被hack,即这个点被删除,又变成 ...
- Hibernate入门这一篇就够了
前言 本博文主要讲解介绍Hibernate框架,ORM的概念和Hibernate入门,相信你们看了就会使用Hibernate了! 什么是Hibernate框架? Hibernate是一种ORM框架,全 ...
- Linux OpenSSH后门的添加与防范
引言:相对于Windows,Linux操作系统的密码较难获取.不过很多Linux服务器配置了OpenSSH服务,在获取root权限的情况下,可以通过修改或者更新OpenSSH代码等方法,截取并保存其S ...
- Android okHttp网络请求库详解
okhttp 是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android.需要Android 2.3以上. 特点 OKHttp是Android版Http客户端.非常高效,支持S ...