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). ...
随机推荐
- Mongo散记--聚合(aggregation)& 查询(Query)
mongo官网:http://www.mongodb.org/ 工作中使用到Mongo,可是没有系统的学习研究过Mongo,仅对工作过程中,在Mongo的使用过程中的一些知识点做一下记录,并随时补充, ...
- 利用分布类防止EF更新模型丢失验证信息
数据库表TT,EF生成的model是这样的.在这里添加代码,从数据库更新模型是会冲掉. //------------------------------------------------------ ...
- Ubuntu Android Studio 无法通过起动器开启
问题: 1.可以通过终端开启 2.通过Android-Studio建立的Application无法启动, 提示 No JDK found. Please validate either STUDIO_ ...
- poj2478--欧拉函数打表
此题中对时间有要求,如直接使用欧拉函数求解,每输入一个n,就得进行循环求出<n的每个数的欧拉函数, 这样会超时, 于是我们可预先将欧拉函数打表, 再进行一个循环加法运算,便可不超时得解. #in ...
- 并发编程: c++11 thread(Func, Args...)利用类成员函数创建线程
c++11是VS2012后支持的新标准,为并发编程提供了方便的std::thread. 使用示例: #include <thread> void thread_func(int arg1, ...
- Programming C#.Classes and Objects.只读字段
只读字段 当字段声明中含有 readonly 修饰符时,该声明所引入的字段为只读字段.给只读字段的直接赋值只能作为声明的组成部分出现,或在同一类中的实例构造函数或静态构造函数中出现.(在这些上下文中, ...
- QF——OC中的KVC,KVO
KVC: (Key Value Coding) 键值编码 所谓KVC,其实就是不通过set和get方法访问对象属性,而是通过属性名字符串动态的去读取属性.KVC其实也是OC反射机制的一种运用. 之所以 ...
- 关于ThreadAbortExcption异常处理
之前程序中,使用Thread.Abort()方法来终止线程的运行,但它是抛出ThreadAbortException异常来终止线程. 异常信息摘要: Unhandled Exception:Threa ...
- OC中NSArray的使用
不可变数组类容器类,管理一组对象类型的数据. 元素是有序的,索引值从0开始 数组中存储的元素必须是对象,类型任意. 创建数组对象,使⽤用实例初始化或便利构造器.获取元素个数.根据索引值获取对 ...
- 帝国cms内容页模版
<title>[!--pagetitle--]</title> <meta name="keywords" content="[!--pag ...