Exponentiation

Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8874    Accepted Submission(s): 2556

Problem 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
 
 
 
情不自禁的感叹:java大法好。
toString()   转成字符串,但数太大或太小时,用科学计数法。
toPlainString()  转成字符串,普通计数。
triptrailingzeros()   去掉最后面后缀0
substring()  取子串
import java.util.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.io.*; public class Main { public static void main(String[] args) {
BigDecimal a;
int n;
double r;
Scanner in=new Scanner(System.in);
while(in.hasNext())
{
r=in.nextDouble();
n=in.nextInt();
a=BigDecimal.valueOf(r);
String s=a.pow(n).stripTrailingZeros().toPlainString();
if("0".equals(s.substring(0,1))&&s.length()>1)
System.out.println(s.substring(1));
else
System.out.println(s);
}
}
}
 
 

HDU_1063_Exponentiation_大数的更多相关文章

  1. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  2. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  3. c语言经典算法——查找一个整数数组中第二大数

    题目: 实现一个函数,查找一个整数数组中第二大数. 算法思想: 设置两个变量max1和max2,用来保存最大数和第二大数,然后将数组剩余的数依次与这两个数比较,如果这个数a比max1大,则先将max1 ...

  4. 杨氏矩阵:查找x是否在矩阵中,第K大数

    参考:http://xudacheng06.blog.163.com/blog/static/4894143320127891610158/ 杨氏矩阵(Young Tableau)是一个很奇妙的数据结 ...

  5. 蓝桥杯算法提高 P1001(大数乘法)

      算法提高 P1001   时间限制:1.0s   内存限制:256.0MB   当两个比较大的整数相乘时,可能会出现数据溢出的情形.为避免溢出,可以采用字符串的方法来实现两个大数之间的乘法. 具体 ...

  6. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

  7. PHP大数(浮点数)取余

    一般我们进行取余运算第一个想到的就是用百分号%,但当除数是个很大的数值,超出了int范围时,这样取余就不准确了. php大数(浮点数)取余函数 /** * php大数取余 * * @param int ...

  8. HDU 5686 斐波那契数列、Java求大数

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=5686 当我们要求f[n]时,可以考虑为前n-1个1的情况有加了一个1. 此时有两种情况:当不适用第n个1进 ...

  9. 区间K 大数查询

      算法训练 区间k大数查询   时间限制:1.0s   内存限制:256.0MB 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列 ...

随机推荐

  1. maven更改镜像路径为阿里镜像,以便下载速度快

    1.maven更改镜像路径为阿里镜像,以便下载速度快 2.maven每更新一次镜像地址,都会重新下载一次包 3. 怎么配maven链接阿里云的镜像详细步骤 修改maven根目录下的conf文件夹中的s ...

  2. OpenFlashChart的图片导出

    http://www.cnblogs.com/mcmurphy/archive/2012/10/15/2724894.html http://teethgrinder.co.uk/open-flash ...

  3. struts2 与spring整合

    要把struts2的action交给spring管理,这样spring才干帮struts2注入须要的的bean(一開始action是由struts初始化,所以想注入spring里面的bean是注入不了 ...

  4. 路由其实也可以很简单-------Asp.net WebAPI学习笔记(一) ASP.NET WebApi技术从入门到实战演练 C#面向服务WebService从入门到精通 DataTable与List<T>相互转换

    路由其实也可以很简单-------Asp.net WebAPI学习笔记(一)   MVC也好,WebAPI也好,据我所知,有部分人是因为复杂的路由,而不想去学的.曾经见过一位程序猿,在他MVC程序中, ...

  5. 设计四个线程,当中共两个线程每次对j添加1,另外两个线程每次对j降低1。循环100次,写出程序。

    package cn.usst.DataTest6; /** * 设计四个线程,当中共两个线程每次对j添加1,另外两个线程每次对j降低1.循环100次,写出程序. * @ * */ public cl ...

  6. LeetCode 977. Squares of a Sorted Array (有序数组的平方)

    题目标签:Array 题目给了我们一组 从小到大的 integers,让我们平方数字 并且 也排序成 从小到达. 因为有负数在里面,平方后,负数在array的位置会变动. 可以设left 和 righ ...

  7. MySQL 登录问题

    1.问题一:使用update mysql.user set password='root'改动密码后,不能登录 解决:操作过程例如以下. (1)关闭mysql(杀掉mysqld进程),然后使用命令: ...

  8. 我不常用的 javascript

    获取当前时间:new Date    (最后的调用括号可加可不加) 获取当前时间戳: 方法1:Date.parse(new Date()) 方法2:(new Date()).valueOf() 方法3 ...

  9. struts2 全局拦截器,显示请求方法和參数

    后台系统中应该须要一个功能那就是将每一个请求的url地址和请求的參数log出来,方便系统调试和bug追踪,使用struts2时能够使用struts2的全局拦截器实现此功能: import java.u ...

  10. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...