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;
}
Codeforces Beta Round #10 C. Digital Root 数学的更多相关文章
- Codeforces Beta Round #10 D. LCIS
题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...
- Codeforces Beta Round #10 D. LCIS 动态规划
D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...
- Codeforces Beta Round #10 B. Cinema Cashier 暴力
B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...
- Codeforces Beta Round #10 A. Power Consumption Calculation 水题
A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...
- Codeforces Beta Round #11 B. Jumping Jack 数学
B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...
- Codeforces Beta Round #10 D. LCIS(DP&LCIS)
D. LCIS time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Beta Round #10 B. Cinema Cashier (树状数组)
题目大意: n波人去k*k的电影院看电影. 要尽量往中间坐,往前坐. 直接枚举,贪心,能坐就坐,坐在离中心近期的地方. #include <cstdio> #include <ios ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
随机推荐
- docker 加速
Docker配置阿里云加速地址 打开阿里云网站https://cr.console.aliyun.com,登陆自己的阿里云账号. 然后只需要在服务器配置docker配置文件,只需要修改"Ex ...
- python基础===对字符串进行左右中对齐
例如,有一个字典如下: >>> dic = { "name": "botoo", "url": "http:// ...
- static作用(修饰函数、局部变量、全局变量)转自http://www.cnblogs.com/stoneJin/archive/2011/09/21/2183313.html
static作用(修饰函数.局部变量.全局变量) 在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条. (1)先来介绍它的第一条也是最重要的一条:隐藏. 当我们同时编译多个文件 ...
- Linux下如何打开img镜像文件
有些镜像文件为IMG格式,在Linux如何打开呢?例如从微软dreampark下载的Windows Server 2008 R2镜像文件,使用file命令查看: $ file chs_windows_ ...
- 不老的神器:安全扫描器Nmap渗透使用指南【转】
介绍 nmap是用来探测计算机网络上的主机和服务的一种安全扫描器.为了绘制网络拓扑图Nmap的发送特制的数据包到目标主机然后对返回数据包进行分析.Nmap是一款枚举和测试网络的强大工具. 特点 主机探 ...
- Python 正则表达式、re模块
一.正则表达式 对字符串的操作的需求几乎无处不在,比如网站注册时输入的手机号.邮箱判断是否合法.虽然可以使用python中的字符串内置函数,但是操作起来非常麻烦,代码冗余不利于重复使用. 正则表达式是 ...
- Jmeter中的变量(三)
变量(Variables) Jmeter中的变量(参数化)目的是为了提供改变请求变化的机制.比如登录场景,一般不能使用同一个账号做并发操作. 变量的特点 1) JMeter变量对于测试线程而言是局部变 ...
- javascript练习(二)
案例 输出100个数字 案例 打印100以内 7的倍数 案例 打印100以内的奇数 案例 打印100以内所有偶数的和 打印图形 ********** ********** ********** ...
- css 资料链接
https://tink.gitbooks.io/fe-collections/content/ch03-css/float.html https://css-tricks.com/almanac/p ...
- IEEEXtreme 9.0 - Digit Fun!
博客中的文章均为 meelo 原创,请务必以链接形式注明 本文地址 Xtreme 9.0 - Digit Fun! 题目来源:第9届IEEE极限编程大赛第1题 Recurrence relations ...