Problem F: Exponentiation大数求幂
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 \le 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
思路:注意当输入1.10000时我是先变成1.1处理
#include<stdio.h>
#include<iostream>
using namespace std;
#include<string.h>
void chengfa(char a[],char b[])
{
int sum[];
int lena=strlen(a)-;
int lenb=strlen(b)-;
int t1=lena;
int t;
memset(sum ,,sizeof(sum));
for(int i=lena;i>=;i--)
for(int j=lenb,t=-(t1-i);j>=;j--)
sum[t--]+=(a[i]-'')*(b[j]-'');
for(int k=;k>=;k--)
{
sum[k-]+=sum[k]/;
sum[k]=sum[k]%;
}
int start=;
while(start<=&&!sum[start])
start++;
memset(a,,sizeof(a));
int t2=;
for(int k=start;k<=;k++)
a[t2++]=sum[k]+'';
a[t2]='\0'; }
int main()
{
char a[],b[];
char a1[],a2[];
int n;
memset(b,,sizeof(b));
while(cin>>a>>n)
{
int k6;
int len6=strlen(a);
for(k6=len6-;k6>=;k6--)
if(a[k6]!='')
{
a[k6+]='\0';
break;
}
int len1=strlen(a);
int k;
for(int i=;i<len1;i++)
if(a[i]=='.')
{ k=(len1-)-i;
int j;
for(j=i;j<len1;j++)
a[j]=a[j+];
a[j]='\0';
len1--;
break; }
int num=k*n;
strcpy(b,a);
n=n-;
while(n--)
chengfa(a,b);
int len2=strlen(a);
int count1=;
int k1,k2,k3,k4;
int lena=strlen(a)-count1;
if(num<lena) 没有前导0,即第一个是数字是大于0
{
for(k1=;k1<lena-num;k1++)
cout<<a[k1];
cout<<'.';
for(k2=k1;k2<lena;k2++)
cout<<a[k2];
cout<<endl;
}
else //有前导0
{ printf(".");
for(k3=num-lena;k3>;k3--)
printf("");
cout<<a;
cout<<endl;
}
}
return ;
}
Problem F: Exponentiation大数求幂的更多相关文章
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
- poj1001 Exponentiation 大数的幂
Description Problems involving the computation of exact values of very large magnitude and precision ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 快速求幂(Quick Exponentiation)
接触ACM没几天,向各路大神求教,听说ACM主要是研究算法,所以便开始了苦逼的算法学习之路.话不多说,RT所示,学习快速求幂. 在头文件<math.h>或是<cmath>中,d ...
- 如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 求幂大法,矩阵快速幂,快速幂模板题--hdu4549
hdu-4549 求幂大法.矩阵快速幂.快速幂 题目 M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 ...
- 大数求模 sicily 1020
Search
- C# 高精度求幂 poj1001
高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...
- 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模
题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...
随机推荐
- Android学习之SQLite学习
花了2天时间,系统学习了下Android开发过程中使用的轻量级数据库SQLite的使用. 并掌握其增,删,该,查的基本数据库操作. 首先要使用SQLite数据库,须要通过Android系统提供的SQL ...
- jquery动态连接节点
<1> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- 你想不到的压缩方法:将javascript文件压缩成PNG图像存储
这样可以做到很高的压缩比,到底有多高,下面会提到.这种方法用到了 canvas 控件,这也意味着只有支持 canvas 控件的浏览器下才有效. 现在你可以看到,上面的图像类似一个噪声图像,但它实际上是 ...
- SQL整理3
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- wcf系列学习5天速成——第五天 服务托管
今天是系列的终结篇,当然要分享一下wcf的托管方面的知识. wcf中托管服务一般有一下四种: Console寄宿: 利于开发调试,但不是生产环境中的最佳实践. winform寄 ...
- Ubuntu自带的vi编辑器太难用了,换
由于Ubuntu预安装的是tiny版本,就会导致我们在使用上的产生不便.所以我们要安装vim的full版本. 首先,先卸掉旧版的vi,输入以下命令: sudo apt-get remove vim-c ...
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session
出错原因很简单:数据库服务没开,自然就打不开Session了.
- LINUX下查看CPU使用率的命令[Z]
1.top 使用权限:所有使用者 使用方式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b] 说明:即时显示process的动态 d :改变显示的更新速度,或 ...
- juce中的引用计数
这个类提供了最基本的引用计数管理,界面库中,经常都需要消息发送,而带来的后果就是不知道消息中包含的对象是否还存在,如果不能很好管理的话就容易出现访问销毁了的对象这样的情况,所以,juce的界面无素也基 ...
- php7 不向后的兼容的变更
php7 不向后的兼容的变更 在php7中,很多致命错误以及可恢复的致命错误,都被转换为异常来处理了. 这些异常继承自Error类,此类实现了Throwable接口(所有异常都实现了这个基础接口) 这 ...