exponentiation
Time Limit: 500MS |
|
Memory Limit: 10000K |
Total Submissions: 147507 |
|
Accepted: 36006 |
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt are a taxing experience for many computer systems.
This problem requires so 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 a integer such that 0 < n <= 25.
Input
The input would consist of a set of pairs of values for R and N. The R value would occupy columns 1 through 6, and the N value would be in columns 8 and 9.
Output
The output would consist of one line for each line of input giving the exact value of r^n. Leading zeros should is suppress Ed in the output. Insignificant trailing zeros must not being printed. Don ' t print the decimal point if the result was an integer.
Sample Input
95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.00000005148554641076956121994511276767154838481760200726351 20383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.7641210216181644302 0690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
Hint
If you don ' t know what to determine wheather encounted the end of input:
sis a string and
Nis an integer
C + +while (cin>>s>>n) {...} cwhile (scanf ("%s%d", S,&n) ==2)//to See If the scanf read on as many items as you Want/*while (scanf (%s%d), s,&n)!=eof)//this also work */{...}
Source
East Central North America 1988
Accode:
#include <iostream> #include <cstring> #include <cstdio> #define MAXN 999999using namespace Std;char a[ 10];int add[10],ans[maxn],res[maxn],n,doc,len;void put1 () {if (doc==-1) {bool Flag=false; for (int i=ans[0];i>=1;--i) {if (ans[i]!=0) flag=true; if (flag) printf ("%d", ans[i]); }} else {doc=5-doc; Doc*=n; int flag1,flag2; for (int i=1;i<=ans[0];++i) if (ans[i]!=0) {flag1=i; Break } for (int i=ans[0];i>=1;--i) if (ans[i]!=0) {flag2=i; Break } if (Flag2<doc) Flag2=doc; if (Flag1>doc) flag1=doc+1; BOOL Flag=false; while (FLAG2>=FLAG1) {if (Flag2==doc) Putchar ('. '); printf ("%d", Ans[flag2]); flag2--; }} putchar (' \ n ');} void Fun () {memset (res,0,sizeof (res)); for (int i=1;i<=ans[0];i++) {for (int j=1;j<=len;j++) {res[i+j-1]+=ans[i]*add[j]; if (res[i+j-1]>9) {res[i+j] + = res[i+j-1]/10; RES[I+J-1]%= 10; }}} if (res[ans[0]+len-1]>9) {RES[ANS[0]+LEN]+=RES[ANS[0]+LEN-1]/10; res[ans[0]+len-1]%=10; } Ans[0]=ans[0]+len; for (int i=1;i<=ans[0];i++) ans[i]=res[i];} int main () {while (cin>>a>>n) {if (n==0) {printf ("1\n"); Continue } memset (ans,0,sizeof (ans)); memset (Add,0,sizeof (a)); doc=-1;len=6; int i,j,cnt=0; for (I=0;i<6;++i) {if (a[i]== '. ') {doc=i; len=5; } if (a[i]== ' 0 ') cnt++; } if (Cnt==len) {printf ("0\n"); Continue } for (I=5,j=1;i>=0;--i) if (i!=doc) {add[j]= (a[i]-' 0 '); ANS[J]=ADD[J]; j + +; } Ans[0]=len; for (I=1;i<n;++i) fun (); PUT1 (); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1001 exponentiation seeking high precision power