E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/**
题目:E - Leading and Trailing
链接:https://vjudge.net/contest/154246#problem/E
题意:求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
思路:后三位求法只要不断对1000取余就行了。
前三位求法:
对一个数x,他可以用科学计数法表示为10^r*a (r为次方,1<=a<10)
设:n^k = x = 10^r*a
两边取对数: k*log10(n) = log10(x) = r+log10(a);
令y = k*log10(n); 因为r是整数,1<=a<10所以0<=log10(a)<1
所以log10(a)为y的小数部分;即log10(a) = y-(long long)y;
a = 10^(y-(long long)y);
最终结果为:(long long)(a*100)即为前三位;
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+;
///后三位
ll Least(ll n,ll k)
{
ll p = ;
while(k>){
if(k&) p = p*n%;
n = n*n%;
k >>= ;
}
return p;
}
///前三位
ll Leading(ll n,ll k)
{
double y = k*log10(n);
double a = pow(10.0,y-(ll)y);
return (ll)(a*);
}
int main()
{
int T, cas=;
ll n, k;
cin>>T;
while(T--){
scanf("%lld%lld",&n,&k);
///注意这里后三位要输出三位。
printf("Case %d: %lld %03lld\n",cas++,Leading(n,k),Least(n,k));
}
return ;
}
E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。的更多相关文章
- 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 ...
- Uva 11029 Leading and Trailing (求n^k前3位和后3位)
题意:给你 n 和 k ,让你求 n^k 的前三位和后三位 思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0 资料:求n^k的前m位 博客连接地址 代码: #include < ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- UVA-11029 Leading and Trailing
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...
- 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...
- LightOj 1282 Leading and Trailing
求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) - ...
- Leading and Trailing(巧妙利用log解决次方问题)
Sample Input 5 123456 1 123456 2 2 31 2 32 29 8751919 Sample Output Case 1: 123 456 Case 2: 152 936 ...
- [题解]UVA11029 Leading and Trailing
链接:http://vjudge.net/problem/viewProblem.action?id=19597 描述:求n^k的前三位数字和后三位数字 思路:题目要解决两个问题.后三位数字可以一边求 ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
随机推荐
- Spring整合jdbc-jdbc模板api详解
1, package com.songyan.jdbc2; public class User { private int id; private String name; public int ge ...
- Android消息机制探索(Handler,Looper,Message,MessageQueue)
概览 Android消息机制是Android操作系统中比较重要的一块.具体使用方法在这里不再阐述,可以参考Android的官方开发文档. 消息机制的主要用途有两方面: 1.线程之间的通信.比如在子线程 ...
- 【MyEcplise】导入项目后,会定时弹出一下错误MyEcplise tern was unable to complete your request in time.This couble happen if your project contains several large javaScript libraies.
Myecplise弹出错误如下: 错误代码: MyEcplise tern was unable to complete your request in time.This couble happen ...
- [ACM] POJ 2151 Check the difficulty of problems (概率+DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4748 ...
- 你是那种仅仅看《XXXXX从入门到精通》的程序猿吗?
我一開始又要废话一番了. 实际上上了大学以后.你常常会在网上,在和别人的交流里,在老师的课堂上.反复听到一些书,比方黄仁宇的<万历十五年>.王小波"时代三部曲".村上春 ...
- php中一些函数的用法
addslashes() 定义和用法 addslashes() 函数返回在预定义字符之前添加反斜杠的字符串. 预定义字符是: 单引号(') 双引号(") 反斜杠(\) NULL 提示:该函数 ...
- javascript - 实现jquery类似的$调用方法
var $ = { name: function (name) { return name; }, age: function (age) { return age; }, numCount: fun ...
- 网络编程基础——学习阻塞,非阻塞(select和epoll)
<h3 class="xyn" helvetica="" neue',="" helvetica,="" aria ...
- win10系统怎样手动安装cab更新补丁
win10系统怎样手动安装cab更新补丁 1. 把所有补丁放进一个文件夹 例如 C:\UPDATE2. 以管理员运行命令提示符 3. 输入以下命令後按 Enterdism /online /add-p ...
- redis源代码分析(5)——aof
前面几篇基本介绍了redis的主要功能.流程.接下来是一些相对独立的部分,首先看一下持久化. redis持久化支持两种方式:RDB和AOF,我们首先看一下AOF的实现. AOF(Append only ...