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 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...
随机推荐
- linguistic相关
Knowing a word means knowing both its sound and its meaning, while being able to use a word requires ...
- Python: PS 滤镜--USM 锐化
本文用 Python 实现 PS 滤镜中的 USM 锐化效果,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/detail ...
- asterisk用 freetds记录 cdr 到mssql
Compile, configure, and install the latest FreeTDS package: [pre] tar -zxvf freetds-0.62.4 ...
- Java连接redis操作数据
选择2.9.0 jar 版本下载: jedis-2.9.0.jar package com.hao.redis; import org.junit.Before;import org.junit.Te ...
- 基于候选区域的R-CNN系列网络简介
使用候选区域方法(region proposal method)创建目标检测的感兴趣区域(ROI).在选择性搜索(selective search,SS)中,首先将每个像素作为一组.然后,计算每一组的 ...
- node.js版本管理(Win) --- nvm-window
目录 1. 安装 2. 使用 1. 安装 去往Git链接:https://github.com/coreybutler/nvm-windows. 点击下载链接: 选择第一个nvm-noinstall. ...
- UVA11624(bfs最短路)
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the m ...
- 升级后,使用dynamic报错
程序升级为.NET 4.0后,在程序中使用dynamic时出现下列错误 错误 5 预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入错误 4 找不 ...
- getElementsByName()获取标签时的注意
var aDiv = document.getElementsByTagName('div');//获取的标签名注意你下面用的是哪一个div的标签名,例如 aDiv[0] 才可以: <!-- 注 ...
- css sprite讲解与使用实例
转自:http://www.manongjc.com/article/886.html 一.什么是css sprites css sprites直译过来就是CSS精灵.通常被解释为“CSS图像拼合”或 ...