【CF10C】Digital Root

题目

题意翻译
定义函数s(x),s(x)的值等于x各数位上的数值之和,定义函数d(x),当s(x)<=9时d(x)=s(x),否则d(x)=d(s(x)),举例来说,d(6543)=d(6+5+4+3)=d(18)=9

现在给定一上限N,求在[1.N]内任取A,B,C满足A*B!=C且d©=d(d(A)⋅d(B))的组数

N<=1000000 Translated by @稀神探女

题目描述
Not long ago Billy came across such a problem, where there were given three natural numbers A A , B B and C C from the range [1,N] [1,N] , and it was asked to check whether the equation AB=C 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) d(x) of the number x x is the sum s(x) s(x) of all the digits of this number, if s(x)<=9 s(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)=9 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)) 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.

输入输出格式
输入格式:
The first line contains the only number N N ( 1<=N<=10^{6} 1<=N<=10
6
).

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

输入输出样例
输入样例#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) .

思路

那么先处理出d(a)⋅d(b)=d©的部分,然后处理出a⋅b=c的部分,两者相减即为答案。

代码

#include <bits/stdc++.h>
#define re register
typedef int mainint;
#define int long long
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=(X<<3)+(X<<1)+c-'0',c=getchar();
    return X*w;
}

int a[10];

mainint main() {
    int n=read();
    int ans1=0,ans2=0;
    for (re int i=1;i<=n;i++) a[i%9]++,ans1+=n/i;
    for (re int i=0;i<9;i++)
        for (re int j=0;j<9;j++)
            ans2+=a[i]*a[j]*a[(i*j)%9];
    printf("%I64d\n",ans2-ans1);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值