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(快速幂 + 数学)的更多相关文章

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

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

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

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

  5. LightOJ 1282 Leading and Trailing (数学)

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

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

  7. [CSP-S模拟测试]:随(快速幂+数学)

    题目描述 给出$n$个正整数$a_1,a_2...a_n$和一个质数mod.一个变量$x$初始为$1$.进行$m$次操作.每次在$n$个数中随机选一个$a_i$,然后$x=x\times a_i$.问 ...

  8. zhx's contest (矩阵快速幂 + 数学推论)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  9. LightOj 1282 Leading and Trailing

    求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) - ...

随机推荐

  1. fcitx jdk maven profile配置

    #小企鹅输入法配置 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS="@im=fcitx&quo ...

  2. 转载:Scalers:要持续行动,不要自我感动

    转载自微信公众号:http://mp.weixin.qq.com/s?__biz=MzA4MjIyNDYzMQ==&mid=2650846277&idx=1&sn=5d832a ...

  3. Python实现插件机制——自动import一个目录下的所有.py文件

    假设有这样一个目录结构: /src          main.py          /plugins                __init__.py                a.py  ...

  4. Qt窗口的屏幕居中显示

    QDesktopWidget *pDesk = QApplication::desktop(); login->move((pDesk->width() - login->width ...

  5. PadLeft 和 PadRight

    1 PadLeft 即:向已知字符串左边补充字符,使整个字符串到达指定长度 CREATE FUNCTION PadLeft ( ),/*原始字符*/ @TotalLength int,/*总长度*/ ...

  6. 8 TIPS TO BECOME A MICROSOFT TECHNICAL EVANGELIST

    8 TIPS TO BECOME A MICROSOFT TECHNICAL EVANGELIST By Thomas Lewis February, 28 2012 I have had a pai ...

  7. ibatis map

    <select id="selectBank2" parameterClass="java.util.Map" resultClass="jav ...

  8. requireJS的引用

    main.js: require.config({ paths: { jquery: 'jquery-1.7.2', biz: 'biz', }}); require(['jquery', 'biz' ...

  9. Git使用心得

    1.git是分布式的版本控制(有本地仓库)git 先对安全 2.git基于元数据   svn是基于目录的 3.本地的提交分为三个步骤(提交本地仓库先提交暂存区再提交本地仓库) 工作区         ...

  10. TTL、RS232、RS485、串口

    Point: 1.串口.COM口是指的物理接口形式(硬件).而TTL.RS-232.RS-485是指的电平标准(电信号). 2.接设备的时候,一般只接GND RX TX.不会接Vcc或者+3.3v的电 ...