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) - ...
随机推荐
- 解决错误 Cannot await in the body of a catch clause
解决错误 Cannot await in the body of a catch clause static async Task f() { ExceptionDispatchInfo ca ...
- python3.5------用户的三次验证
笔者QQ: 360212316 逻辑图 代码 #/usr/bin/python # -*- coding: utf-8 -*- lock = open("black_user_list.tx ...
- poj1050
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39081 Accepted: 20639 Desc ...
- EXCEL数据导入dataset
一.开工必备 1.micorosoft office2007 2.VS2010.Oracle 11 二.界面 三.内部代码 (1)获取数据库连接,定义全局变量 private static strin ...
- openfire 连接sqlserver 2008 的一个问题
由于本人的笨拙,搞了一天才终于搞好,说实在的问题归根结底还是在sql上,要相信openfire是没问题的.好了,不瞎扯了,说正题. 本人的机器环境为:win7.sqlserver 2008.jdk1. ...
- win8 VB6打开提示MSCOMCTL.ocx未注册
从xp上复制相应的文件到win8相应的位置,如果是不可以,win8中反注册此控件,再注册此控件
- springbootboot-HttpServletRequest.getInputStream() 获取post内容
问题描述: 在php端用curl post一段json到java springboot.在java端用request.getInputStream()获取到的数据为空. 问题确认: 询问度娘后, 她告 ...
- 第13章 .NET应用程序配置
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- C# 科学计数法转换成数字
/// <summary> /// 判断输入的数是否是科学计数法.如果是的话,就会将其换算成整数并且返回,否则就返回false. /// </summary> /// < ...
- 10款免费而优秀的图表JS插件
http://www.open-open.com/lib/view/open1406378625726.html http://www.ichartjs.com http://echarts.baid ...