(n 的 n 次方之和) 计算1^1 + 2^2 + 3^3 + … + ? 的高精度值。(1 ≤ ? ≤ 20),试补全该程序。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include<iostream> #include<string.h> using namespace std; const int MAXN=250; int n, t, i, j, k, la, lb, x[10], a[MAXN], b[MAXN]; void f(int *a){ for(int i = 0; i < MAXN; i++){ if(a[i] >= 10){ a[i+1] += a[i] / 10; a[i] %= 10; } } } int main(){ cin>>n; ①; for(i=2;i<= 9;i++){ t=1; for(j=1;j<=i;j++){ t*=i; } x[i]=t; } for(i=2;i<=9;i++) ②; if(!(n/10)) cout << x[n]; else{ for(k=i;k<=n;k++){ memset(a,0,sizeof(a)); t=k,la=0; while(t){ a[la++]=t%10; t/=10; } for(i=2;i<=k;i++){ for(j=0;j<la;j++) a[j]*=k; ③; t=MAXN; while(!a[t]) t--; la=t + 1; } for(i=0;i<la;i++) b[i]+=a[i]; f(b); lb = ④; if(b[lb]) lb++; } t=⑤, i=0; while(t){ b[i]+=t%10; t/=10; i++; } f(b); for(i=lb-1;i>=0;i--) cout << b[i]; } return 0; } |
0 of 5 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 5 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
①处应填( )。
②处应填( )。
③处应填( )。
④处应填( )。
⑤处应填( )。