CodeForces 10C. Digital Root

乞讨A。B。C ∈[1。N] && A*B != C,d(A*B) == d(C)组的数量。

首先要知道d(x) = (x%9 == 0 ? 9 : x%9);

那么则会有A*B == C,则必有d(A*B) == d(C)。

若不考虑A*B != C,则答案既是ans[x]*ans[y]*ans[d(x*y)],ans[x]为d(i) == x的个数,显然x∈[1,9]。

当考虑A*B != C时。则须要从ans[x]*ans[y]*ans[d(x*y)] - sum。

sum = sigma(n/i) , i ∈[1。n]。

int main()
{

    int n,i,j,tmp;

    scanf("%d",&n);

    LL anw = 0;

    for(i = 1;i <= n; ++i)
    {
        ans[(tmp = i%9) == 0 ?

9 : tmp]++; anw -= n/i; } for(i = 1;i <= 9; ++i) for(j = 1;j <= 9; ++j) anw += ans[i]*ans[j]*ans[(tmp = (i*j)%9) == 0 ? 9 : tmp]; printf("%I64d ",anw); return 0; }


版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4877219.html