Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created September 2, 2019 08:33
Show Gist options
  • Save surinoel/2954e03847792090361dd4e675117d05 to your computer and use it in GitHub Desktop.
Save surinoel/2954e03847792090361dd4e675117d05 to your computer and use it in GitHub Desktop.
#include <cmath>
#include <string>
#include <iostream>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s = to_string(n);
int len = s.size();
int ans = 0;
ans = len * (n - (int)pow(10, len - 1) + 1);
for (int i = len - 1; i >= 1; i--) {
ans += 9 * (int)pow(10, i - 1) * i;
}
cout << ans << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment