【1013】Sn的公式求和

在这里插入图片描述

 # include<iostream>
 using namespace std;
 int main(){
     int n;
     cin >> n;
     int sum = 0, a = 2,total_sum = 0;
     for (int i = 1; i <= n; i++){
         sum = (sum * 10) + a;
         total_sum += sum;
     }
     cout << total_sum << endl;
     return 0;
 }