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 中的一个数 做法分析 先这样考 ...
随机推荐
- ASLR pe 分析
ASLR 转:http://www.cnblogs.com/dliv3/p/6411814.html 3ks @author:dlive 微软从windows vista/windows server ...
- curl 发送请求的时候报错
AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see ...
- ASPLOS'17论文导读——SC-DCNN: Highly-Scalable Deep Convolutional Neural Network using Stochastic Computing
今年去参加了ASPLOS 2017大会,这个会议总体来说我感觉偏系统和偏软一点,涉及硬件的相对少一些,对我这个喜欢算法以及硬件架构的菜鸟来说并不算非常契合.中间记录了几篇相对比较有趣的paper,今天 ...
- 湖南省第十一届大学生程序设计竞赛:Internet of Lights and Switches(HASH+二分+异或前缀和)
Internet of Lights and Switches Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3 Solved: 3[Submit][ ...
- 清除(设置)eclipse的workspace记录
在eclipse文件夹中找到这个文件即可: //eclipse/configuration/.settings/org.eclipse.ui.ide.prefs 用记事本打开这个文件.如果你是第一次打 ...
- c++ primer 5 表达式
简单总结下容易忽视的地方和易错点吧 1 常用的位操作符,leecode很多算法题都是靠位运算解决的 2 箭头操作符 -> 等价于(* ). 对指针的成员操作 3 sizeof操作符 对 c ...
- 用strtok函数分割字符串
用strtok函数分割字符串 需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. //Body response 内容: <BODY><; PRE&g ...
- shell-命令行参数(转)
命令行参数 (转自http://c.biancheng.net/cpp/view/2739.html) 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字, ...
- ref:ubuntu下如何批量修改文件后缀名
ref:https://blog.csdn.net/whuslei/article/details/6724900 ubuntu下如何批量修改文件后缀名 正确的方法是: 在命令行中输入 renam ...
- 洛谷P1403 [AHOI2005] 约数研究 [数论分块]
题目传送门 约数研究 题目描述 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机“Samuel II”的长时间运算成为了可能.由于在去年一年的辛苦工作取得了不错的成绩, ...