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 Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.

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

有趣的大数幂运算,如果直接用BigDecimal的话会错误,需要进行一点小小的处理。

import java.math.BigDecimal;
import java.util.Scanner; /**
*
* @author Asimple
* @date ${date}
*
*/ public class Main{ public static BigDecimal fun(BigDecimal num, int n) {
if( n==1 ) return num;
if( n%2==0 ) return fun(num,n/2).multiply(fun(num,n/2));
else return fun(num,n/2).multiply(fun(num,n/2)).multiply(num);
} static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
BigDecimal a;
int n;
while( sc.hasNext() ) {
a = sc.nextBigDecimal();
n = sc.nextInt();
String ans = "";
ans = fun(a,n).stripTrailingZeros().toPlainString();
if(ans.charAt(0) == '0') {
int i;
for(i=0; i<ans.length(); i++)
if(ans.charAt(i) != '0')
break;
System.out.println(ans.substring(i));
}
else System.out.println(ans);
}
}
}

UVA - 748 Exponentiation的更多相关文章

  1. uva 748 Exponentiation 浮点数乘方运算 高精度水题

    输入的前六位数表示一个小数,然后输入一个数表示几次方.要求用高精度算出结果. 高精度水题,主要注意处理小数点,先在输入时把小数点提取出来并记录位置,用普通乘法计算出结果后由后向前计算位置添加小数点. ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. Volume 1. Big Number(uva)

    如用到bign类参见大整数加减乘除模板 424 - Integer Inquiry #include <iostream> #include <string> #include ...

  4. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)

    这里的高精度都是要去掉前导0的, 第一题:424 - Integer Inquiry UVA:http://uva.onlinejudge.org/index.php?option=com_onlin ...

  5. uva748 - Exponentiation

    import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class Exponenti ...

  6. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. vue.js-moment的使用

    1.安装: npm install moment --save 2.引入:import moment from 'moment.js' 3.moment("时间").format( ...

  2. OpenCV矩形检测

    OpenCV矩形检测 需求:提取图像中的矩形,图像存在污染现象,即矩形区域不是完全规则的矩形. 思路一:轮廓法 OpenCV里提取目标轮廓的函数是findContours,它的输入图像是一幅二值图像, ...

  3. Scala泛型[T]的使用

    package com.dtspark.scala.basics /** * 1,scala的类和方法.函数都可以是泛型. * * 2,关于对类型边界的限定分为上边界和下边界(对类进行限制) * 上边 ...

  4. eclipse回退到上个版本

    在  team->show in history 中 选择版本,执行Revert Commit,然后push 到master,这样就可以了

  5. Django 框架 基本知识

    一.什么事web框架 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支持结构,使用框架可以使我们快速开发特定的系统,简单来说,就是讲实现方式的底层结构进行封装,提供相应的 ...

  6. win10系统180天试用到期需要激活

    激活时激活不了,需要先修复下:4-Win10yjjh_XiTongZhiJia 链接: https://pan.baidu.com/s/1M_aNu2bqtEVn3l8FXsa91A 提取码: 784 ...

  7. android 通过页面上关键字快速定位代码

    这里定位微信关于页面, 当然可以直接获取当前最顶层activity 反编译apk后 搜索 strings.xml,找到对应id 搜索文件到用到id对应的成员变量,通常 是在R*.smali文件中 字符 ...

  8. python对字典及列表递归排序

    对字典内所有内容进行排升序排序,包括,子数组,子字典 需要注意: 1.字典因为是在一定程序上无序的,所以这里采用了内置包,来变成有序字典 from collections import Ordered ...

  9. 学习笔记: ES7(ES2016)新功能

    ES7添加了两个新功能 : 1. Array.prototype.includes() 2. 指数运算符 1 .Array.prototype,includes() 判断指定的元素是否存在于数组中,  ...

  10. LeetCode14.最长公共前缀

    编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow" ...