long long calc(long long a) {
if (a < 10) return a;
long long r = a / 10;
r += 8;
long long f = a;
while (f >= 10) f /= 10;
if (f <= a % 10) r++;
return r;
}
long long calc(long long a) {
if (a < 10) return a;
long long r = a / 10;
r += 8;
long long f = a;
while (f >= 10) f /= 10;
if (f <= a % 10) r++;
return r;
}
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3390 |
| 6 | Um_nik | 3387 |
| 7 | tourist | 3384 |
| 8 | heuristica | 3322 |
| 9 | turmax | 3319 |
| 10 | jiangbowen | 3291 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 143 |
| 5 | AmShZ | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | maroonrk | 134 |
| 9 | BledDest | 132 |
| 10 | qwexd | 129 |
| Название |
|---|



Function
calc(a)computes number of all good numbers which are less of equal to a.if (a < 10) return a;— in case of one-digit input.It's simple to prove that each tenth number is good (first and last digits are equal):
Don't forget about one-digit numbers:
Let's compute the first digit f of the number a
and check whether (a div 10 * 10 + f) <= a:
"It’s simple to prove that each tenth number is good (first and last digits are equal): long long r = a / 10;" not able to understand the above lines and one digit numbers should be 1 to 9(why 8) please explain??
Ok, assume that a % 10 == 0. (Last string checks another case)
For t > 0 every interval [ t * 10, (t + 1) * 10 ) contains exactly one good number. So the interval [10, a) contains
(a - 10) / 10good numbers, ora / 10 - 1. Add nine one-digit numbers and geta / 10 - 1 + 9 = a / 10 + 8.