单ゑ计 (geometric series)
单ゑ计计厩﹚竡
璝兜 aそゑ r兜计 n玥玡 n 兜单ゑ计㎝
sn= a + ar + ar2 + ... + ar(n-1)
ㄤい璝 ar(n-1) = an玥
sn-1 = a1 + a2 + a3 + ... + an-1
sn = sn-1 + an
璝患癹ㄧ计 sum(n) = sn = a1 + a2 + a3 + ... + an
玥 sum(n) = sum(n-1) + an
玥ㄧ计砞璸よΑ
1.  a 籔 d ぃ穦э跑祘Αよ獽┦砞 a 籔 d 办┦跑计
2.患癹ㄢ璶
    A.sum(n) 籔 sum(n-1) 闽玒 sum(n) = a+(n-1)*d + sum(n-1)
    B.sum(1) = 1

癹伴
患癹

#include <stdio.h>
#include <stdlib.h>
int a, r;

int main(){
int i, k, s, n;
scanf("%d %d %d",&a,&r,&n);
s=0; k=1;
for(i=1;i<=n;i++){
    s+=a*k;
    k*=r;
}
printf("s=%d\n",s);
return(0);
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int a, r;

int sum(int n){
if(n==1)
    return(a);
else
    return(a*pow(r, n-1)+sum(n-1));
}

int main(){
int i, k, s, n;
scanf("%d %d %d",&a,&r,&n);
s=sum(n);
printf("s=%d\n",s);
return(0);
}