CF10C.Digital Root

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root d(x) of the number x is the sum s(x) of all the digits of this number, if s(x) ≤ 9, otherwise it is d(s(x)). For example, a digital root of the number 6543 is calculated as follows: d(6543) = d(6 + 5 + 4 + 3) = d(18) = 9. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. d(xy) = d(d(x)d(y)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes.

不久之前,Billy 遇到了这样一个问题:给定范围 [1,N][1, N] 内的三个自然数 AA、BB 和 CC,要求判断等式 AB=CAB = C 是否成立。最近,Billy 学习了数字根(digital root)的概念。我们提醒您,一个数 xx 的数字根 d(x)d(x) 定义如下:若 xx 各位数字之和 s(x)≤9s(x) \leq 9,则 d(x)=s(x)d(x) = s(x);否则 d(x)=d(s(x))d(x) = d(s(x))。例如,数 65436543 的数字根计算过程为:d(6543)=d(6+5+4+3)=d(18)=9d(6543) = d(6 + 5 + 4 + 3) = d(18) = 9。Billy 发现,乘积的数字根等于各因子数字根之积的数字根,即 d(xy)=d(d(x)d(y))d(xy) = d(d(x)d(y))。于是他想到了如下解法:分别计算 AA、BB、CC 的数字根,并检验是否满足 d(d(A)d(B))=d(C)d(d(A)d(B)) = d(C)。然而,Billy 怀疑该条件并不充分。因此,他请您找出:对于给定的 NN,在所有满足 1≤A,B,C≤N1 \le A, B, C \le N 的三元组 (A,B,C)(A, B, C) 中,有多少组使得 Billy 提出的算法判断错误(即:实际 AB≠CAB \ne C,但 d(d(A)d(B))=d(C)d(d(A)d(B)) = d(C) 成立;或实际 AB=CAB = C,但 d(d(A)d(B))≠d(C)d(d(A)d(B)) \ne d(C) 成立)。

输入格式

The first line contains the only number N (1 ≤ N ≤ 106).

第一行包含唯一一个数字 NN(1 ≤ N ≤ 1061 \leq N \leq 10^6)。

输出格式

Output one number — the amount of required A, B and C from the range [1, N].

输出一个数字——在区间 [1, N][1,\,N] 内满足要求的 A、B 和 C 的个数。

输入输出样例

  • 输入#1

    4

    输出#1

    2
  • 输入#2

    5

    输出#2

    6

说明/提示

For the first sample the required triples are (3, 4, 3) and (4, 3, 3).

对于第一个样例,所需的三元组为 (3, 4, 3)(3,\,4,\,3) 和 (4, 3, 3)(4,\,3,\,3)。

输入解题思路,AI测评打分。不知道怎么写?

首页