首页 > 其他 > 详细

CodeForces 10C. Digital Root

时间:2014-10-26 21:17:07      阅读:301      评论:0      收藏:0      [点我收藏+]

求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\n",anw);

    return 0;
}

CodeForces 10C. Digital Root

原文:http://blog.csdn.net/zmx354/article/details/40480147

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!