• Codeforces Beta Round #10 C. Digital Root 数学


    C. Digital Root

    题目连接:

    http://www.codeforces.com/contest/10/problem/C

    Description

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

    Input

    The first line contains the only number N (1 ≤ N ≤ 106).

    Output

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

    Sample Input

    4

    Sample Output

    2

    Hint

    题意

    问你[1,n]中有多少 AB!=C,但是D(A)D(B)=D(C)的

    D(A)是数根的意思,翻译过来就是这个数%9

    题解:

    容斥做,首先把所有的D(A)D(B)=D(C)的计算过来

    然后减去AB==C且D(A)D(B)=D(C)的,由于显然AB=C,那么D(A)D(B)=D(C)

    所以我们只需要减去AB=C的就好了,我们暴力枚举A,看B的个数有n/A个

    然后莽一波……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    int a[10];
    int main()
    {
        int n;long long ans = 0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)a[i%9]++,ans-=n/i;
        for(int i=0;i<9;i++)for(int j=0;j<9;j++)ans+=1ll*a[i]*a[j]*a[i*j%9];
        cout<<ans<<endl;
    }
  • 相关阅读:
    Appium+unittest+PageObject实例
    monkeyrunner简单用法
    Mac电脑修改系统文件夹的权限
    UIImage剪切
    LLDB 打印 frame
    打开qq在线聊天
    获取当地时间
    微信支付SDK使用心得
    获取当前星期几
    UIView相对于屏幕的frame
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5439079.html
Copyright © 2020-2023  润新知