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). ...
随机推荐
- xCode6制作动态及静态Framework(转)
原文:http://years.im/Home/Article/detail/id/52.html 相关推荐:http://www.cocoachina.com/ios/20150127/11022. ...
- REST和JAX-RS相关知识介绍
REST REpresentational State Transfer:代表性状态传输.具象状态传输 REST定义了应该如何正确地使用Web标准,例如HTTP和URI.REST并非标准,而是一种开发 ...
- 使用Vitamio打造自己的Android万能播放器(1)——准备
前言 虽然Android已经内置了VideoView组件和MediaPlayer类来支持开发视频播放器,但支持格式.性能等各方面都十分有限,这里与大家一起利用免费的Vitamio来打造属于自己的And ...
- VB.NET函数——数学函数/字母串函数
一.数学函数 函数 说明 Abs (num) 取绝对值. Exp (num) 返回以e为底.以num为指数的值,如Exp(2)返回e^2值. Log (num) 返回参数num的自然对数值,为Doub ...
- OC-方法
1.类声明 @interface Person : NSObject { @public int _height; int _weight; int _age; } // 如果你不想每次使用方法都需要 ...
- 常用封装--Date篇--获取格式化的日期对象
虽然日期对象可以使用new Date()来获取,但是对于其格式却必须进行相应的转换,才能成为开发者想要的格式. 这里提供了一个封装的方法,通过结合正则表达式的使用,达到了可以对时间对象进行处理,生成多 ...
- 简单的BFS学习笔记
什么是BFS传送门. 今天学习BFS,加油! 先定义个数组: struct Node{ int a=0; int b=0; int step=0; }; int map[5][4]={//地图 0,0 ...
- Linux学习之tail命令
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- python退格、方向键无法正常使用解决方法
CentOS 6.5 自带的Python 2.6.6 箭头以及退格键(Backspace)可正常使用: 自定义所安装的Python 2.7.6却发现箭头以及退格键(Backspace)在使用的时候出现 ...
- charset
<meta charset="UTF-8" /> 这是html5的写法. <meta http-equiv=“content-type” content=“tex ...