#abc336e. E - Digit Sum Divisible

E - Digit Sum Divisible

Score: 525525 points

问题描述

在正整数 nn 中,其数字和被定义为 nn 的十进制表示中所有数字的和。例如,数字 20242024 的数字和为 2+0+2+4=82+0+2+4=8

一个正整数 nn 被称为良数,当且仅当 nn 可以被它的数字和整除。例如,20242024 是一个良数,因为它可以被其数字和 88 整除。

现在给定一个正整数 NN,请计算不大于 NN 的良数有多少个?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

The digit sum of a positive integer nn is defined as the sum of the digits in the decimal notation of nn. For example, the digit sum of 20242024 is 2+0+2+4=82+0+2+4=8.
A positive integer nn is called a good integer when nn is divisible by its digit sum. For example, 20242024 is a good integer because it is divisible by its digit sum of 88.
You are given a positive integer NN. How many good integers are less than or equal to NN?

Constraints

  • 1N10141 \leq N \leq 10^{14}
  • NN is an integer.

Input

The input is given from Standard Input in the following format:

NN

Output

Print the number of good integers less than or equal to NN.

Sample Input 1

20

Sample Output 1

13

There are 1313 good integers less than or equal to 2020: 1,2,3,4,5,6,7,8,9,10,12,18,201,2,3,4,5,6,7,8,9,10,12,18,20.

Sample Input 2

2024

Sample Output 2

409

Sample Input 3

9876543210

Sample Output 3

547452239

update @ 2024/3/10 01:25:34