light OJ 1282 - Leading and Trailing 数学 || double技巧
http://lightoj.com/volume_showproblem.php?problem=1282



#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset> //int calc(LL a, LL b, int k) { //a^b的前k + 1位
// double res = b * log10(a * 1.0) - (LL)(b * log10(a * 1.0)); //小数部分
// return (int)pow(10.0, k + res);
//}
int calc(double a, LL b, int k) {
double ans = , base = a;
while (b) {
if (b & ) {
ans = ans * base;
}
b >>= ;
base = base * base;
while (ans >= ) ans /= ; //保留前3位
while (base >= ) base /= ;
}
return (int)ans;
}
int quick_pow(LL a, LL b, int MOD) {
LL ans = , base = a % MOD;
while (b) {
if (b & ) ans = ans * base % MOD;
b >>= ;
base = base * base % MOD;
}
return ans;
}
void work() {
LL a, b;
cin >> a >> b;
static int f = ;
printf("Case %d: %d %03d\n", ++f, calc(a, b, ), quick_pow(a, b, ));
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
light OJ 1282 - Leading and Trailing 数学 || double技巧的更多相关文章
- 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 ...
- LightOJ 1282 Leading and Trailing (数学)
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后 ...
- LightOJ - 1282 - Leading and Trailing(数学技巧,快速幂取余)
链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- 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 ...
- 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...
- LightOJ 1282 Leading and Trailing 数论
题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x* ...
- LightOJ - 1282 Leading and Trailing (数论)
题意:求nk的前三位和后三位. 分析: 1.后三位快速幂取模,注意不足三位补前导零. 补前导零:假如nk为1234005,快速幂取模后,得到的数是5,因此输出要补前导零. 2.前三位: 令n=10a, ...
- Light OJ 1032 - Fast Bit Calculations(数学)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...
随机推荐
- Python: PS 图像调整--饱和度调整
本文用 Python 实现 PS 图像调整中的饱和度调整算法,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...
- codevs 1147 排座椅
传送门 题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接 ...
- 19.break和continue
break;语句: 1.可以在switch语句中,结束分支语句: 2.break:语句可以出现在单循环当中,默认情况下结束距离他最近的一个循环. 3.break 后面跟一个循环的名字可以结束你指定的这 ...
- 纯css 图片自适应居中
html 结构 <div class="container"> <div class="content"></div> &l ...
- P-Function
题意: 对于集合 $S = {1, 2, ...., n}$ , 定义函数 $F(x) = y, x, y$ 属于 $S$,对于任何 $x$ 属于 $S$, 有 $F(F...F(x)) = x$, ...
- 使用jdk获取网页
参考:https://www.zhihu.com/question/30626103 由于例子比较老了,现在的百度抓不到完整的页面了 import java.io.BufferedReader; im ...
- Makefile研究 (一)—— 必备语法
摘自:http://blog.csdn.net/jundic/article/details/17535445 参考文档:http://blog.csdn.net/wrx1721267632/arti ...
- POJ 3662 Telephone Lines (二分+dijkstra)
题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...
- Lightoj1003【判环操作】
题意: 对于n个给出字符串a,b,理解成a在b之前办好这个事情,要求n个给出两个串,a都要在b之前完成: 题意: 所以一旦出现环就不行了: 以前在写最短路的时候,spfa就有一个判环,后来写着写着写到 ...
- Spring Boot 创建自定义的properties文件
以IDEA2018为例,在资源文件夹上点击鼠标右键,依次选择 New -> Resource Bundle ,如下图: 在弹出的对话框中,填写properties文件的名称(不用填写.prope ...