标签:style blog for sp 2014 log amp ef as
求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; }
标签:style blog for sp 2014 log amp ef as
原文地址:http://blog.csdn.net/zmx354/article/details/40480147