Exponentiation(高精度大数)
Exponentiation
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
Hint
If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
//计算 n 的 x 次方
//显然,是个大数题,正好来练练java,格式要控制好。
import java.math.BigDecimal;
import java.util.Scanner;
import java.lang.String; /**
* Created by happy_code on 2017/6/6.
*/
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s;
int n;
while (sc.hasNext())
{
s=sc.next();
n=sc.nextInt();
BigDecimal base = new BigDecimal(s);
BigDecimal res = new BigDecimal("");
for (int i=;i<n;i++){
res = res.multiply(base);
}
String ans = res.toPlainString(); boolean ok = false;
int k;
for (k =;k<ans.length();k++){
if (ans.charAt(k)=='.'){
ok = true;
break;
}
}
int e=ans.length()-;
if (ok){
while(ans.charAt(e)=='') e--;
if (ans.charAt(e)=='.') e--;
}
int i = ;
while(ans.charAt(i)=='') i++;
for (;i<=e;i++){
if (i==&&ans.charAt(i)==''){
continue;
}
System.out.print(ans.charAt(i));
}
System.out.println();
}
}
}
Exponentiation(高精度大数)的更多相关文章
- uva748 - Exponentiation 高精度小数的幂运算
uva748 - Exponentiation Exponentiation Problems involving the computation of exact values of very ...
- Exponentiation java大数
Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...
- hdu 1063 Exponentiation (高精度小数乘法)
//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...
- 1001. Exponentiation高精度运算总结
解题思路 这道题属于高精度乘法运算,要求输入一个实数R一个指数N,求实数R的N次方,由于R有5个数位,而N又特别大,因此用C++自带的数据类型放不下. 解题思路是通过数组储存每次乘积结果和底数的每一位 ...
- 【POJ 1001】Exponentiation (高精度乘法+快速幂)
BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...
- Hdu 4762 网络赛 高精度大数模板+概率
注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放, ...
- POJ-1001 Exponentiation 高精度算法
题目链接:https://cn.vjudge.net/problem/POJ-1001 以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得, 现在把代码都般过来,等会把旧电脑弄一弄,暂时就不 ...
- PAT A1024题解——高精度大数相加模板
PAT:A1024 Palindromic Number A number that will be the same when it is written forwards or backwards ...
随机推荐
- vue - rimraf
rimraf 包的作用:以包的形式包装rm -rf命令,用来删除文件和文件夹的,不管文件夹是否为空,都可删除 const rimraf = require('rimraf'); rimraf('./t ...
- iOS开发-Object-C学习之结构体使用
前言:定义结构体并不是定义一个变量,而是定义了种数据类型. 结构体作用: 结构体和其他类型基础数据类型一样,例如int类型,char类型 只不过结构体可以做成你想要的数据类型.以方便日后的使用. 在实 ...
- 利用pandas进行数据分析之一:pandas数据结构Series
Series是一种类似于一维数组的对象,又一组数据(各种Numpy数据类型)以及一组与之相关的数据标签(即是索引)组成. 可以将Series看成是一个定长的有序字段,因为它是索引值到数据值的一个映射. ...
- where 泛型类型参数及约束
private void InsertData<TRowMetadata, TFieldMetadata, TCellMetadata>(IMetadataReader<TRowMe ...
- RabbitMQ消息队基本概念
RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.消息中间件主要用于组件之间的 ...
- tony_nginx_01_如何在linux系统下安装nginx、pcre、zlib、openssl工具
nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息. 正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好. ububtu平台编译环 ...
- CentOS 加载/挂载光驱
1.mkdir /mnt/cdrom 2.mount /dev/cdrom /mnt/cdrom 3.挂载 umount /dev/cdrom /mnt/cdrom
- SpringBoot支持https和http
1.application.propertites #server.port=8081 server.port: 8443 server.ssl.key-store: classpath:keysto ...
- java & c sharp 的关联
第一.java是真正的与平台无关,c sharp不是,他只是口头上的与平台无关,最后,却要靠别人来实现非微软平台的类库. 第二.java中的类名.class 和c#的 typeof(类名)或者getT ...
- 指尖上的电商---(11)Windows平台部署SolrCloud
SolrCloud是一种分布式解决方式,是基于zookeeper和solr的,能够简单理解为一种集群,能够提供分布式查询.分布式写索引. SolrCloud的结构大致是这种,一个SolrCloud包含 ...