#include<iostream>#include<vector>usingnamespace std;
vector<int> sn;voidCalSn(constint a,constint num){int number =1, i =0;int sum =0;while(i < num ){if(0== i){
sn.push_back(a * number);}else{
sn.push_back(a * number + sn.at(i -1));}
number = number *10;
sum += sn.at(i);
i++;}
cout <<"Sn=a+aa+aaa+…+aa…aaa(有n"<<"("<<num<<")"<<"个a"<<"("<<a<<"))的值为:"<<sum << endl;}intmain(){int a =2, n =5;
cout <<"请输入a的值:";
cin >> a;
cout <<"请输入n的值:";
cin >> n;CalSn(a, n );return0;}