[题解]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得前三位数字以及后三位数字, ...
随机推荐
- Vscode不能连接应用商店
删除这两个文件即可: 1.C:\Users\Administrator\.vscode 2.C:\Users\Administrator\AppData\Roaming\Code
- 集合框架-工具类-Arrays-asList方法
1 package cn.itcast.p3.toolclass.arrays.demo; 2 3 import java.util.ArrayList; 4 import java.util.Arr ...
- 查看WordPress网站使用的主题和插件
阅读原文 whatwpthemeisthat.com 很多时候在网上看到某个WordPress的主题很漂亮,很想要这个主题,又联系不上博客的联系人的时候,我们可以通过以下方法进行查看. 一.手动扒代码 ...
- proxy_buffer代理缓冲区
目录 一:代理缓冲区 1.代理缓存区模块介绍 二:案例 1.配置文件 2.测试 3.重启 4.lb01服务器(负载均衡) 5.网址配置文件 6.测试 7.重启 8.DNS解析 9.网址测试 10.日志 ...
- python29day
内容回顾 网络编程 概念 B/S C/S架构 B/S browser server C/S client 装客户端使用的 server远程服务器的 osi七层协议 今日内容 tcp协议的编程 如何在连 ...
- 如何保存并复制python虚拟环境
关于虚拟环境的一些基础概念学习了本期视频 保存 以我的一个虚拟环境示例: 在要保存的虚拟环境下使用: pip freeze > requirements.txt 复制 pip install - ...
- pycharm 安装插件
1.使用pip安装插件 pip安装指定版本的插件: pip install openpyxl==2.6.2 -i https://pypi.doubanio.com/simple/ -i后面跟的是&q ...
- SpringBoot 简单介绍
一.springboot是啥? 1.什么是springboot? 1.1springboot是spring生态圈的一个轻量级框架,换句话说springboot就是spring,是spring的一个衍生 ...
- Spring源码-IOC部分-自定义IOC容器及Bean解析注册【4】
实验环境:spring-framework-5.0.2.jdk8.gradle4.3.1 Spring源码-IOC部分-容器简介[1] Spring源码-IOC部分-容器初始化过程[2] Spring ...
- js中全局变量和局部变量以及变量声明提升
javascript中全局变量和局部变量的区别 转载前端小99 发布于2018-04-23 15:31:35 阅读数 2102 收藏 展开 [javascript] view plain copy ...