Exponentiation
Time Limit: 500MS   Memory Limit: 10000K
Total Submissions: 158025   Accepted: 38470

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
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=;
struct BigInt{
int e[MAXN],len,pp;
BigInt()
{
memset(e,,sizeof(e));
len=;
pp=;
}
void set(const char s[])
{
int l=strlen(s);
for(int i=;i<l;i++)
{
if(s[i]=='.')
{
pp=l-i-;
continue;
}
e[len++]=s[i]-'';
}
for(int i=;i<len/;i++)
{
int t=e[i];
e[i]=e[len-i-];
e[len-i-]=t;
}
while(len>&&e[len-]==) len--;
}
BigInt operator*(const BigInt &b)
{
BigInt ret;
for(int i=;i<len;i++)
{
int up=;
for(int j=;j<b.len;j++)
{
int z=e[i]*b.e[j]+up+ret.e[i+j];
ret.e[i+j]=z%;
up=z/;
}
if(up!=)
{
ret.e[i+b.len]=up;
}
}
ret.len=len+b.len;
ret.pp=pp+b.pp;
while(ret.len>&&ret.e[ret.len-]==) ret.len--;
return ret;
}
void print()
{
int limit=;
while(e[limit]==&&limit<pp) limit++;//去后导0
if(pp>=len)
{
printf(".");
for(int i=pp;i>len;i--)
{
printf("");
}
for(int i=len-;i>=limit;i--)
{
printf("%d",e[i]);
}
printf("\n");
}
else
{
for(int i=len-;i>=pp;i--)
{
printf("%d",e[i]);
}
if(limit<pp)
{
printf(".");
for(int i=pp-;i>=limit;i--)
{
printf("%d",e[i]);
}
}
printf("\n");
}
}
};
char buf[];
int n;
int main()
{
while(scanf("%s%d",buf,&n)!=EOF)
{
BigInt t;
t.set(buf);
BigInt res;
res.set("1.0");
for(int i=;i<n;i++)
{
res=res*t;
}
res.print();
}
return ;
}

POJ1001(C++处理大数)的更多相关文章

  1. poj1001 Exponentiation【java大数】

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

  2. poj1001 Exponentiation 大数的幂

    Description Problems involving the computation of exact values of very large magnitude and precision ...

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

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

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

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

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

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

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

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

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

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

  8. 51nod 1005 大数加法

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

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

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

随机推荐

  1. 20179209《Linux内核原理与分析》第十二周作

    缓冲区溢出漏洞实验 缓冲区溢出简介 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况.这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段.这一漏洞的出现是由于数据缓冲器 ...

  2. MainWindows

    开发带有菜单栏状态栏等常用windows应用时候使用

  3. iOS UITableView滚动头图 拉伸放大效果 (头部弹性效果) 增加iOS11支持 附有demo

    今天修改日期为2017年11月25日 两个月前做了iOS11的bug修复,才对博客进行更新,见谅. 在iOS11上需要注意两个问题 1.使用UIScrollview,UITableView,UIWeb ...

  4. HDR(High Dynamic Range) - 高动态范围

    1. Dynamic Range 动态范围是指一个场景的最亮和最暗部分之间的相对比值   2. Tone-mapping 现实真正存在的亮度差,即最亮的物体亮度和最暗的物体亮度之比为 , 而人类的眼睛 ...

  5. 转 Hadoop傻瓜化:Datameer大数据收入翻三番

      淘薛奎发布到 <数据极客> 06-28 16:04 随着分析正在成为企业IT的核心,昔日的BI- ETL-EDW分析范型已经完全落伍,不再适用.而力推“大数据傻瓜化”的Datameer ...

  6. 《程序员代码面试指南》第二章 链表问题 删除中间节点和a/b处节点

    题目 例如 1-2-3-4 删除2,1-2-3-4-5 删除3 例如 a=1,b =2 java代码 /** * @Description:删除中间节点和a/b处节点 * @Author: lizho ...

  7. 【leetcode刷题笔记】Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  8. 20145229吴姗珊 《Java程序设计》课程总结

    20145229吴姗珊 <Java程序设计>课程总结 (按顺序)每周读书笔记链接汇总 第一周:http://www.cnblogs.com/20145229ss/p/5248728.htm ...

  9. /etc/apt/sources.list

    今天学习: 在Ubuntu下软件源的文件是/etc/apt/sources.list,那么sourdces.list.d目录下的文件又是什么作用呢? 该文件夹下的文件是第三方软件的源,可以分别存放不同 ...

  10. Luogu-1381 单词背诵

    先将n个单词插入哈希表,记录左右端点,每次右端点往后移动,读入一个新的单词并记录下它的哈希值,如果这个单词之前没出现过那么更新\(ans\)和\(minl\),如果左端点的单词出现了不止一次则可以往右 ...