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 /

{

}

#include <iostream>
#include <string.h>
using namespace std;
int a[200];
int main()
{
int n,i,j;
string s;
while(cin>>s>>n)
{
memset(a,0,sizeof(a));
if(n == 0)
{
cout<<1<<endl;
continue;
}
bool flag = 1;
int pos = 0,base = 0,count = 0,bit = 1;
for(i = s.length()-1,j = 0; i >= 0; i--)
{
if(s[i] == '0'&&flag) count++;
else
{
flag = 0;
if(s[i] == '.')
pos = s.length()-count-i-1;
else
{
a[j++] = s[i] - '0';
base += (s[i] - '0')*bit;
bit *= 10;
} }
}
for(i = 0; i < n-1; i++)
{
int m = 0;
for(j = 0; j < 300; j++)
{
m += base * a[j];
a[j] = m % 10;
m /= 10;
}
}
for(i = 299; a[i] == 0&&i > pos*n-1; i--);
while(i >= 0)
{
if(i == pos*n-1)
cout<<".";
cout<<a[i];
i--;
}
cout<<endl;
}
return 0;
}

求高精度幂(poj1001)的更多相关文章

  1. Poj.Grids 2951 浮点数求高精度幂

    2951:浮点数求高精度幂 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方. ...

  2. 求高精度幂(java)

    求高精度幂 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...

  3. 【ACM】求高精度幂

    题目来源:http://poj.org/problem?id=1001&lang=zh-CN 求高精度幂 Time Limit: 500MS   Memory Limit: 10000K To ...

  4. poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 180325   Accepted: 43460 Descripti ...

  5. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  6. poj 1001 求高精度幂

    本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果: 95.123 12 548815620517731830194541.899025343415715973535 ...

  7. C# 高精度求幂 poj1001

    高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...

  8. HDU 1402 A * B Problem Plus (FFT求高精度乘法)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. 使用java求高精度除法,要求保留N位小数

    题目要求是高精度除法,要求保留N位小数(四舍五入),并且当整数部分为0时去除0的显示 import java.math.BigDecimal; import java.util.Scanner; pu ...

随机推荐

  1. 彻底解决_OBJC_CLASS_$_某文件名", referenced from:问题

    最近在使用静态库时,总是出现这个问题.下面总结一下我得解决方法: 1. .m文件没有导入    在Build Phases里的Compile Sources 中添加报错的文件 2. .framewor ...

  2. 两小时快速构建微信小程序

    小程序在2017年1月上线之初,被社会极力吹捧,刻意去将其制造为一个“风口”,透支其价值.但是在之后一个月里,石破天惊迅速归为沉寂.媒体又开始过度消费小程序,大谈其鸡肋之处. 个人认为小程序的一个分水 ...

  3. MSSQL 构建临时表SQL

    declare @StartQuarter int declare @StartYear int declare @EndQuarter int declare @EndYear int declar ...

  4. 【转】jpeg文件格式详解

    JPEG(Joint Photographic Experts Group)是联合图像专家小组的英文缩写.它由国际电话与电报咨询委员会CCITT(The International Telegraph ...

  5. face_recognition 人脸识别报错

    [root@localhost examples]# python facerec_from_video_file.py RuntimeError: module compiled against A ...

  6. 判断cookie创建的时间是否已经24小时

    def read_cookie(self): cookiesfilepath="cookies%s" % self.uid if os.path.exists(cookiesfil ...

  7. jdk1.8在linux环境下的安装

    转自博客:http://www.cnblogs.com/ShawnYuki/p/6816179.html

  8. yii2 一对多关系的对分页造成的影响

    下面代码中关联descies时,匹配较多,造成分页数不对,需要加条件限制: $model = User::find() ->joinWith('app') ->joinWith(['des ...

  9. IntelliJ IDEA 启动方法

    IntelliJ IDEA cd idea-IU-145.1617.8/bin && ./idea.sh

  10. 封装ajax方法

    function ajaxRequest(type, url, data, callback, loading, cache) { var ajaxConfig = { url: '', data: ...