数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

 

题目传送门

 1 /*  2  水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:)  3 */  4 #include <cstdio>  5 #include <iostream>  6 #include <algorithm>  7 #include <cstring>  8 #include <cmath>  9 #include <vector> 10 #include <string> 11 #include <queue> 12 #include <map> 13 #include <set> 14 using namespace std; 15 16 typedef long long ll; 17 const int MAXN = 1e2 + 10; 18 const int INF = 0x3f3f3f3f; 19 20 int main(void) //Codeforces Round #308 (Div. 2) B. Vanya and Books 21 { 22 // freopen ("B.in", "r", stdin); 23 24  ll n; 25 while (scanf ("%I64d", &n) == 1) 26  { 27 int len = 0; ll tmp = n; 28 while (tmp) 29  { 30 tmp /= 10; len++; 31  } 32 33 ll ans = 0; ll x = 9; 34 for (int i=1; i<=len-1; ++i) 35  { 36 ans += x * i; x *= 10; 37  } 38 ll y = 1; 39 for (int i=1; i<=len-1; ++i) y *= 10; 40 41 ans += (n - y + 1) * len; 42 printf ("%I64d\n", ans); 43  } 44 45 46 return 0; 47 }

 

你可能感兴趣的:(codeforces)