[题解]UVA11029 Leading and Trailing
链接:http://vjudge.net/problem/viewProblem.action?id=19597
描述:求n^k的前三位数字和后三位数字
思路:题目要解决两个问题。后三位数字可以一边求高次幂一边取模,下面给出求前三位数字的方法。
n^k = (10^lg n)^k = 10^(k*lg n)
为了描述方便,令X=n^k 。则 lg X 的整数部分表示X有多少位。设整数部分为zs,小数部分为xs,则X=(10^zs)*(10^xs) 。 (10^zs)的形式就是100……,跟X的位数一样,那么(10^xs)就是在100……的基础上修饰每一位上的数字,使之成为X。那么(10^xs)*100就是X的前三位(没想清楚的朋友可以在纸上划一划)。
下面给出我的实现。
1 #include <iostream>
2 #include <cstdio>
3 #include <cmath>
4 using namespace std;
5 #define MOD 1000
6 int T,N,K;
7 int Trail;
8 double Lead;
9 inline void Get_int(int &Ret)
10 {
11 char ch;
12 bool flag=false;
13 for(;ch=getchar(),ch<'0'||ch>'9';)
14 if(ch=='-')
15 flag=true;
16 for(Ret=ch-'0';ch=getchar(),ch>='0'&&ch<='9';Ret=Ret*10+ch-'0');
17 flag&&(Ret=-Ret);
18 }
19 int My_Pow(int n,int k)
20 {
21 if(k==1)
22 return n%MOD;
23 int p=My_Pow(n,k/2);
24 if(k%2)
25 return (p*p*(n%MOD))%MOD;
26 return (p*p)%MOD;
27 }
28 int main()
29 {
30 Get_int(T);
31 while(T--)
32 {
33 Get_int(N);Get_int(K);
34 Lead=(double)K*log10(N);
35 Lead=Lead-(int)Lead;
36 Lead=pow((double)10,2+Lead);
37 Trail=My_Pow(N,K);
38 printf("%d...%03d\n",(int)Lead,Trail);
39 }
40 return 0;
41 }
[题解]UVA11029 Leading and Trailing的更多相关文章
- UVA-11029 Leading and Trailing
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...
- uva11029 - Leading and Trailing
题目: 求n的k次方,然后将答案用前三位和最后三位表示. Sample Input 2 123456 1 123456 2 Sample Output 123...456 152...936 分析: ...
- Leading and Trailing LightOJ - 1282 题解
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31} ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- Leading and Trailing (数论)
Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...
- E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...
随机推荐
- RabbitMQ 中的分布式,普通 cluster 模式的构建
RabbitMQ 如何做分布式 前言 集群配置方案 cluster 普通模式 镜像模式 federation shovel 节点类型 RAM node Disk node 集群的搭建 1.局域网配置 ...
- Go 循环控制
#### Go 循环控制昨天有工作要忙, 断更一天,不过学习的事情,还是每天要坚持; 我还有头发, 还能学习^_^.***倘若我心中的山水, 你眼中都看到***上一节学习完流程控制,总结一下switc ...
- linux可用内存判断
free是完全没有占用的空闲内存,Available 减 free是操作系统为了优化运行速度拿来调用的内存, 程序需要的话操作系统会进行释放.所以一般看Available即可. free+buffer ...
- JavaScript之 函数节流(Throttling) 与 防抖(Debounce)
Throttling:在监听鼠标移动事件.盒子滚动事件等使用节流技术能节省性能消耗 /** * 节流函数(每隔t执行一次) */ function Throttling(fn, t) { const ...
- maven 中的工程依赖和层级依赖?
一.什么是工程依赖? 思考问题?1.1一旦开始分模块开发的时候,之前的所有包都会被拆分成一个一个的项目 model mapper service ... 其实mapper需要model的支持,怎么解决 ...
- Spring源码-IOC部分-Spring是如何解决Bean循环依赖的【6】
实验环境:spring-framework-5.0.2.jdk8.gradle4.3.1 Spring源码-IOC部分-容器简介[1] Spring源码-IOC部分-容器初始化过程[2] Spring ...
- ApacheCN 数据科学译文集 20210313 更新
新增了五个教程: Python 和 Jupyter 机器学习入门 零.前言 一.Jupyter 基础知识 二.数据清理和高级机器学习 三.Web 爬取和交互式可视化 Python 数据科学和机器学习实 ...
- Entity Framework 在OrderBy排序中使用字符串
public static class LinqExtensions { private static PropertyInfo GetPropertyInfo(Type objType, strin ...
- fckeditor for php 上传图片文件名中文乱码,中文文章乱码
转载请注明来源:https://www.cnblogs.com/hookjc/ 中文名乱码是因为:FCKeditor使用UTF-8编码,自己机子比如是Windows系统文件名使用的是GBK编码,在上传 ...
- 【转】zabbix监控mysql
纯属搬家收藏,原文链接 https://www.cnblogs.com/shenjianyu/p/6627843.html 注意: 1.关注的重点在agent端部分 2.zabbix_get命令没有, ...