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) - ...
随机推荐
- How to: Convert Between Various String Types
This topic demonstrates how to convert various Visual C++ string types into other strings. The str ...
- 关于C转汇编(转自网上)
②在KILE软件的菜单中,选择Project-->Options for Target 'Target 1',-->Listing选择Assembly code就能生产*.LST文件.在 ...
- nodejs+mysql
接着上一篇的php+mysql,我们来试一试nodejs怎么实现数据的增删查改. Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境.Node.js 使用了一个事件 ...
- 关于odbc的彻底删除问题
最近在装一个软件,由于第一次安装产生了一个错误,于是我尝试在卸载之后,重新进行安装~但是,在安装过程当中出现了一个问题. NEWLRE ODBC data source already exists. ...
- PHP判断请求是否是ajax请求
首先看一下框架里面是怎样判断的.ThinkPHP:define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && str ...
- 关于struts2中的相对路径与绝对路径
从昨天开始复习了struts2的课程,之所以重新走上java的道路,是觉得写了一年的go程序,并没有感觉到学习了什么,反而把java给忘得干干净净的.想想我的计划,年后就要换工作了,至于要换到什么方向 ...
- scala 学习之:List fold, foldLeft方法
先从一道题开始看: Eliminate consecutive duplicates of list elements. If a list contains repeated elements th ...
- Qt之QMutex
概述 QMutex 类使得线程之间可序列化,文档中的描述为provides access serialization between threads 它被设计的初衷是用来保护一个对象.数据结构.代码段 ...
- HDU 1251统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- [整理]一个有关Latch(锁存器)的有趣问题
起源 今天诳论坛,突然发现了一个有关latch的问题,由于对D Flip-Flop和Latch还有些疑问,就点击了进去,一看果然有些意思,也挺有学习意义的,于是本文就诞生了.喊出口号~Just not ...