1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282
题目大意: 求n的k次方的前三位和后三位数然后输出
后三位是用快速幂做的,我刚开始还是不会快速幂,后来慢慢理解了。
前三位求得比较厉害
我们可以吧n^k = a.bc * 10.0^m;
k*log10(n) = log10(a.bc) + m;
m为k * lg(n)的整数部分,lg(a.bc)为k * lg(n)的小数部分;
x = log10(a.bc) = k*log10(n) - m = k*log10(n) - (int)k*log10(n);
x = pow(10.0, x);
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue> using namespace std;
typedef long long int LL;
#define N 1001000
#define ESP 1e-8
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a)) int Pow(int a, int b, int c)
{
if(b == )
return ;
LL t = Pow(a, b>>, c); t = t*t%c;
if(b% == )
t = t*a%c; return t;
}///快速幂 int main()
{
int T, t=;
scanf("%d", &T);
while(T --)
{
int n, k;
scanf("%d %d", &n, &k); double m = k*log10(n) - (LL)(k*log10(n));
m = pow(10.0, m); int ans = Pow(n, k, ); printf("Case %d: %d %03d\n", t++, (int)(m*), ans);
}
return ;
}
1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)的更多相关文章
- 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 ...
- LightOJ - 1282 - Leading and Trailing(数学技巧,快速幂取余)
链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to ...
- 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....,不用要,只要小数部分就好,然后 ...
- Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏
C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- [CSP-S模拟测试]:随(快速幂+数学)
题目描述 给出$n$个正整数$a_1,a_2...a_n$和一个质数mod.一个变量$x$初始为$1$.进行$m$次操作.每次在$n$个数中随机选一个$a_i$,然后$x=x\times a_i$.问 ...
- zhx's contest (矩阵快速幂 + 数学推论)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- LightOj 1282 Leading and Trailing
求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) - ...
随机推荐
- git和github
GIT是一款分布式版本控制系统.与SVN相比可以不依赖网络,并且对分支和合并有更好的支持.但是命令稍微复杂一些,这里简单介绍使用git将项目上传到github. 首先GIT安装只需要去官网下载安装即可 ...
- mongodb morphia关联查询一例
//...此处省略了import... /** * Created by shenzhigang on 4/15/16. */ public class Main { public static vo ...
- poj1985 Cow Marathon (求树的直径)
Cow Marathon Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 3195 Accepted: 1596 Case ...
- JOSN 为空数据的处理
for(var i=0,l=thisuserList.length;i<l;i++){ for(var key in thisuserList[i]){ if(thisuserList[i][k ...
- Python爬虫个人梳理(代码有空写)
这里多是摘抄的,只是用于个人理解. 1.urlopen().read()是爬取网页的内容,出来可能是一堆的源代码.和我们右击网页查看是一样的. 2.当用到http请求的时候,我们可以使用Request ...
- 图像上传OSS的BUG
今天遇到了一个流上传BUG. 图像经过压缩后传到阿里OSS上后无法显示,下载后发现图像大小为0KB. 调试发现上传的时候发现处理后的流大小正确. 最后发现是流经过图像处理后没有复位. 使用res.Se ...
- Linux 常用命令 :ls命令
ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...
- win10家庭版快速升级专业版
win10家庭普通版升级专业版方法: 1.点击“开始”,选择控制面板. 2.点击“系统与安全”,选择“Windows Anytime Upgrade”.(或者:单击「开始」按钮,在搜索框中,键入any ...
- LeetCode OJ 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- hdu 3579 Hello Kiki (中国剩余定理)
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...