CF10C.Digital Root

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Not long ago Billy came across such a problem, where there were given three natural numbers AA , BB and CC from the range [1,N][1,N] , and it was asked to check whether the equation AB=CAB=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)d(x) of the number xx is the sum s(x)s(x) of all the digits of this number, if s(x)<=9s(x)<=9 , otherwise it is d(s(x))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)=9d(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))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 遇到了这样一个问题:给定了三个自然数 AABBCC,范围在 [1,N][1, N],问题是要检查方程 AB=CAB = C 是否正确。最近 Billy 学习了数字的数根概念。我们应该提醒你,数字 xx 的数根 d(x)d(x) 是这个数字所有数字的总和 s(x)s(x),如果 s(x)9s(x) ≤ 9,否则它是 d(s(x))d(s(x))。例如,数字 6543 的数根计算如下: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))。他想到了以下解决问题的方法:计算数根并检查是否满足这个条件。然而,Billy 怀疑这个条件是否足够。这就是为什么他要求你找出给定问题的测试示例数量,使得 Billy 提出的算法出错。

感谢Macw提供翻译

输入格式

The first line contains the only number NN ( 1<=N<=1061<=N<=10^{6} ).

输入一个整数 N(1N106)N (1 \le N \le 10^6)

输出格式

Output one number — the amount of required AA , BB and CC from the range [1,N][1,N] .

输出一个整数,表示在询问区间内满足条件的A,B,CA, B, C的个数。

输入输出样例

  • 输入#1

    4
    

    输出#1

    2
    
  • 输入#2

    5
    

    输出#2

    6
    

说明/提示

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

请注意,本题时间限制为2s,是默认时间限制的两倍。空间限制为256MB,是默认空间限制的两倍。

首页