Exponentiation
Time Limit: 500MS   Memory Limit: 10000K
Total Submissions: 183034   Accepted: 44062

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

C++

while(cin>>s>>n)

{

...

}

c

while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want

/*while(scanf(%s%d",s,&n)!=EOF) //this also work */

{

...

}

Source

题意:

给定一个浮点数R和一个整数n,求R^n

思路:

想给学弟们出一道大数巩固一下。搜到的大数例题。

java BigDecimal自己也都还没用过。

两个点,用 String s = r.pow(n).stripTrailingZeros().toPlainString();使结果不用科学计数法。

注意去掉前导零。比如0.00001要变成 .00001

 import java.io.EOFException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner; public class Main { static public void main(String[] args){
Scanner scan = new Scanner(System.in);
BigDecimal r;
int n;
while(scan.hasNext()){
r = scan.nextBigDecimal();
n = scan.nextInt();
String s = r.pow(n).stripTrailingZeros().toPlainString();
if(s.startsWith("0")){
s = s.substring(1);
}
System.out.println(s);
}
scan.close();
}
}

poj1001 Exponentiation【java大数】的更多相关文章

  1. Exponentiation java大数

    Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...

  2. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  3. java大数

    java大数还是很好用的! 基本加入: import java.math.BigInteger; import jave.math.BigDecimal; 分别是大数和大浮点数. 首先读入可以用: S ...

  4. JAVA大数运算

    java大数是个好东西,用起来方便,代码短. 代码如下: import java.util.*; import java.math.*; public class Main { public stat ...

  5. java大数总结【转】

    java大数(2013长春网络赛)--hdu4762总结一下:1.java提交类要写Main.2.读取大数. Scanner read=new Scanner(System.in); BigInteg ...

  6. HDU5047Sawtooth(java大数)

    HDU5047Sawtooth(java大数) 题目链接 题目大意:在一个矩形内画n个"M".问如何画可以把这个矩形分成最多的区域. 给出这个区域的数目. 解题思路:最好的方式就是 ...

  7. JAVA大数类

    JAVA大数类api http://man.ddvip.com/program/java_api_zh/java/math/BigInteger.html#method_summary 不仅仅只能查J ...

  8. HDU4762(JAVA大数)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. ZOJ3477&JAVA大数类

    转:http://blog.csdn.net/sunkun2013/article/details/11822927 import java.util.*; import java.math.BigI ...

  10. 多校第五场 归并排序+暴力矩阵乘+模拟+java大数&amp;记忆化递归

    HDU 4911 Inversion 考点:归并排序 思路:这题呀比赛的时候忘了知道能够用归并排序算出逆序数,可是忘了归并排序的实质了.然后不会做-- 由于看到题上说是相邻的两个数才干交换的时候.感觉 ...

随机推荐

  1. js获取iframe里面的元素

    直接获取不行 var  win2 = document.querySelector('iframe[width = "1280" ]').contentWindow; var lo ...

  2. highcharts图表中级入门:非histock图表的highcharts图表如何让图表产生滚动条

    最近highcharts图表讨论群里面很多朋友都在问如何让highcharts图表在X轴数据多的情况下产生滚动条的问题,其实之前有一个解决办法是将装载图表的div容器用css样式表弄一个滚动条出来.这 ...

  3. SpEL、PropertyPlaceholderConfigurer与@Value、#{}、${}

    概念 SpEL:Spring EL表达式 PropertyPlaceholderConfigurer:即org.springframework.beans.factory.config.Propert ...

  4. ubuntu 13.04 nginx.conf 配置详解

    1.nginx.conf 文件,路径为:/etc/nginx/agin.conf #使用的用户和组 user www-data; #指定工作衍生进程数(一般等于CPU总核数或总核数的两倍) worke ...

  5. 联想一体机u盘启动设置

    开机启动按f12键,进入后,到最后一项exit把OS Optimized Defaults(操作系统优化的缺省值)改成Disabled(关闭). 再进入到Startup这一项,选择UEFI/Legac ...

  6. Python 文件学习笔记

    程序1 在上一题的基础上扩展,用户可以随意输入要显示的行数. 如输入2:5表示打印第2行到第5行的内容: 输入:2表示打印从开头到第2行的内容: 输入4:表示打印从第4行到结尾的内容: 输入:表示打印 ...

  7. CMake区分MSVC版本

    MSVC++ 4.x _MSC_VER == 1000 MSVC++ 5.0 _MSC_VER == 1100 MSVC++ 6.0 _MSC_VER == 1200 MSVC++ 7.0 _MSC_ ...

  8. python中json格式数据输出实现方式

    python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...

  9. STL源码剖析—顺序容器

    一.vector 1.vector简介: vector的数据安排及其操作方式与数组非常相似,微小的差别在于空间的使用,数组是静态空间,一旦配置了就不能改变.vector是动态空间,随着元素的加入,它的 ...

  10. 怎么修改wamp的本地时间

    最近配置了一台wamp环境的服务器,但发现时间与本地时间是地区别的,并且 利用time获取的时间再利用date显示有时差的,下面我们一起来导致原因与解决办法. 如果date时间不一致可以使用date_ ...