[题解]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得前三位数字以及后三位数字, ...
随机推荐
- Cplex用法
Cplex用法 1.将问题转化为LP问题: cplex -c read mps/nw460.mps change problem type lp opt 2.将问题转化为LP问题并输出问题: cple ...
- 【刷题-LeetCode】150 Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...
- 猪齿鱼 Choerodon 的数据初始化设计解析
数智化效能平台猪齿鱼Choerodon 作为一个微服务框架,需要解决微服务数据初始化本身具有的问题和复杂性,同时也需要满足框架本身特有的数据初始化需求,下面为大家介绍一下这方面的设计思想和实现. 微服 ...
- node.js在Linux下执行shell命令、.sh脚本
首先,引入子进程模块 var process = require('child_process'); 执行shell命令 调用该模块暴露出来的方法exec process.exec('shutdown ...
- java单例模式(饿汉式和懒汉式)
1 /* 2 * 设计模式:对问题行之有效的解决方式.其实它是一种思想. 3 * 4 * 1,单例设计模式 5 * 解决的问题:就是可以保证一个类在内容中的对象唯一性. 6 * 7 * 必须对于多个程 ...
- 基于Python的某大学某学院新生高考成绩分析
# coding=gbk import pandas as pd import numpy as np import matplotlib.pyplot as plt from pylab impor ...
- CDNDrive 第一个版本发布 & 布客新知第二次备份完成
CDNDrive 第一个版本发布,新适配五个图床 https://github.com/apachecn/CDNDrive 另外,布客新知第二次备份完成 TutorialsPoint:http://i ...
- 防火墙——firewalld
介绍 firewald是对于iptables的一个封装,可以让你更容易地管理iptables规则.firewalld是iptables前端控制器,用于实现持久地网络流量规则. 一.对比 firewal ...
- Android返回键
感谢大佬:https://www.cnblogs.com/qiluboy/p/5308310.html Android中back键和home键的区别: back键 Android的程序无需刻意的去退出 ...
- 【密码学工具】Ciphey和WinDecrypto的使用随笔
1.Ciphey 官方文档 这个工具安装起来也很容易,用pip下载即可. pip install ciphey -i https://pypi.mirrors.ustc.edu.cn/simple/ ...