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技巧的更多相关文章

  1. 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 ...

  2. LightOJ 1282 Leading and Trailing (数学)

    题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后 ...

  3. LightOJ - 1282 - Leading and Trailing(数学技巧,快速幂取余)

    链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to ...

  4. LightOJ 1282 Leading and Trailing (快数幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Me ...

  5. 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 ...

  6. 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...

  7. LightOJ 1282 Leading and Trailing 数论

    题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x* ...

  8. LightOJ - 1282 Leading and Trailing (数论)

    题意:求nk的前三位和后三位. 分析: 1.后三位快速幂取模,注意不足三位补前导零. 补前导零:假如nk为1234005,快速幂取模后,得到的数是5,因此输出要补前导零. 2.前三位: 令n=10a, ...

  9. Light OJ 1032 - Fast Bit Calculations(数学)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...

随机推荐

  1. ansible 文件模块,很实用

    摘自: http://blog.csdn.net/kellyseeme/article/details/50545521

  2. ffplay 一些好玩的filter

    添加字幕:ffplay -vf drawtext="fontfile=arial.ttf: text='Test Text': x=100: y=300: \ fontsize=48: fo ...

  3. HDU2602(01背包)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. ASP.NET:Global.asax

    ylbtech-.Net-ASP.NET:Global.asax 1.返回顶部 1. 一.定义:Global.asax 文件(也称为 ASP.NET 应用程序文件)是一个可选的文件,该文件包含响应 A ...

  5. nohup 命令 print 不能实时输出至 nohup.out

    1. 原因 Python 的输出存在缓冲机制,因此不能实时输出结果至 nohup.out 2. 解决方案 用下面的命令即可解决: nohup python -u FileName > nohup ...

  6. Manasa and Combinatorics

    题意: 给定n,求问由2n个字母B,n个字母A构成的字符串中 任意前缀B的个数大于A的个数且任意后缀B的个数大于A的个数的 字符串个数. 解法: 注意到答案不易于直接计算,所以我们考虑应用容斥原理. ...

  7. Laravel中的模型的创建

    <?phpnamespace App; use Illuminate\Database\Eloquent\Model; class Admin extends Model{ //指定表名 pro ...

  8. CSS动画的性能分析和浏览器GPU加速

    此文已由作者袁申授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 有数的数据大屏可以在一块屏幕上展示若干张不同的图表,以炫酷的方式展示各种业务数据.其中有些图表使用CSS实现了 ...

  9. ObjectARX反应器概述[转载]

    何为反应器? AutoCAD中提供了类似MFC消息机制的通知方式.用于处理以下情况: 执行AutoCAD命令.修改系统变量.保存和退出图形编辑器或者切换当前工作布局空间等等. 反应器机制是观察者模式的 ...

  10. 在OpenCV for Android 2.4.5中使用SURF(nonfree module)

    http://blog.csdn.net/ruifdu/article/details/9120559 在OpenCV4Android中没有nonfree module,因此也就没有了SURF和SIF ...