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;
}

Codeforces Beta Round #10 C. Digital Root 数学的更多相关文章

  1. Codeforces Beta Round #10 D. LCIS

    题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...

  2. Codeforces Beta Round #10 D. LCIS 动态规划

    D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...

  3. Codeforces Beta Round #10 B. Cinema Cashier 暴力

    B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...

  4. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  5. Codeforces Beta Round #11 B. Jumping Jack 数学

    B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...

  6. Codeforces Beta Round #10 D. LCIS(DP&amp;LCIS)

    D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  7. Codeforces Beta Round #10 B. Cinema Cashier (树状数组)

    题目大意: n波人去k*k的电影院看电影. 要尽量往中间坐,往前坐. 直接枚举,贪心,能坐就坐,坐在离中心近期的地方. #include <cstdio> #include <ios ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

随机推荐

  1. 选择问题(选择数组中第K小的数)

    由排序问题可以引申出选择问题,选择问题就是选择并返回数组中第k小的数,如果把数组全部排好序,在返回第k小的数,也能正确返回,但是这无疑做了很多无用功,由上篇博客中提到的快速排序,稍稍修改下就可以以较小 ...

  2. 安装ssh-keygen

    转载自:http://www.daoan.com/forums/index.php?forumid=5&mods=topicdisplay&postid=4 sudo apt-get ...

  3. AJP与HTTP比较和分析

    系统环境: OS:Ubuntu 10.10 (2G) Servlet Container:tomcat-tomcat-7.0.23  (最大内存:default 256M  maxThreads:50 ...

  4. [How to] 使用HBase协处理器---Endpoint服务端的实现

    1.简介 前篇文章[How to] 使用HBase协处理器---基本概念和regionObserver的简单实现中提到了两种不同的协处理器,并且实现了regionObserver. 本文将介绍如何使用 ...

  5. CentOS6.9下安装MariaDB10.2.11

    yum groupinstall -y "Development Tools" yum install -y cmake openssl-devel zlib-devel yum ...

  6. 尝试 TFS Express 2012.3

    之前一直使用SVN做版本管理,但是只能管理代码.之前的一份工作,只用了TFS来管理,可以将任务与代码集成管理,很是方便,只是安装太过于繁琐,现在的公司人少,不想费那么多事. 最关键的,就是安装TFS需 ...

  7. vue js moment.js 过滤了双休日和法定节假日

    源码:注!原创的!!!! <template> <div id="DATE"> <ul class="dateForm" @cha ...

  8. bzoj 1855 dp + 单调队列优化

    思路:很容易写出dp方程,很容易看出能用单调队列优化.. #include<bits/stdc++.h> #define LL long long #define fi first #de ...

  9. Java 如何调用 oracle 的存储过程

    通过命令行创建存储过程 create or replace procedure emp_sal(eno emp.empno%type,esal out emp.sal%type) as begin s ...

  10. Java经典设计模式之七大结构型模式

    转载: Java经典设计模式之七大结构型模式 博主在大三的时候有上过设计模式这一门课,但是当时很多都基本没有听懂,重点是也没有细听,因为觉得没什么卵用,硬是要搞那么复杂干嘛.因此设计模式建议工作半年以 ...