codeforces 10C Digital Root(非原创)
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].
Example
4
2
5
6
Note
For the first sample the required triples are (3, 4, 3) and (4, 3, 3).
这题理解了题意就很好做。
转自:https://www.cnblogs.com/qscqesze/p/5439079.html
题意
问你[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个
然后莽一波……
注意,数根是1+(i-1)%9
数根的推导:http://blog.csdn.net/ray0354315/article/details/53991199
附ac代码:
1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <string>
5 #include <cstring>
6 #include <algorithm>
7 #include <queue>
8 #include <map>
9 #include <vector>
10 using namespace std;
11 const int maxn = 1e6+10;
12 typedef long long ll;
13 const ll mod = 1e9+7;
14 const int inf = 0x3f3f3f3f;
15 const double eps=1e-6;
16 ll ans[maxn];
17 int main() {
18 ios::sync_with_stdio(false);
19 int n;
20 cin>>n;
21 ll sum=0;
22 for(int i=1;i<=n;++i) ans[1+(i-1)%9]++,sum-=n/i;
23 for(int i=1;i<=9;++i)
24 {
25 for(int j=1;j<=9;++j)
26 {
27 sum+=ans[i]*ans[j]*ans[1+(i*j-1)%9];
28 }
29 }
30 cout<<sum<<endl;
31 return 0;
32 }
codeforces 10C Digital Root(非原创)的更多相关文章
- CodeForces 10C. Digital Root
乞讨A.B.C ∈[1.N] && A*B != C,d(A*B) == d(C)组的数量. 首先要知道d(x) = (x%9 == 0 ? 9 : x%9); 那么则会有A*B == ...
- Codeforces 10C Digital Root 法冠军
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- Codeforces Beta Round #10 C. Digital Root 数学
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- Linux下high CPU分析心得【非原创】
非原创,搬运至此以作笔记, 原地址:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高ga ...
- 用RD,GR,BL三个方法内代码生成一张图片(非原创,我只是完整了代码)
我公开以下图片的源代码,,是ppm格式的,,自己找到能打开的工具.. (非原创,我加工的代码,可直接执行运行输出,缩略图能看到效果) 这是原博客 http://news.cnblogs.com/n/ ...
- Digital Root 的推导
背景 在LeetCode上遇到这道题:Add Digits 大意是给一个数,把它各位数字相加得到一个数,如果这个数小于10就返回,不然继续 addDigits(这个相加得到的数). 题目很简单,但是如 ...
- 老男孩Django笔记(非原创)
.WEB框架 MVC Model View Controller 数据库 模板文件 业务处理 MTV Model Template View 数据库 模板文件 业务处理 ############## ...
- Digital root(数根)
关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这 ...
随机推荐
- 全网最全!彻底弄透Java处理GMT/UTC日期时间
目录 前言 本文提纲 版本约定 正文 Date类型实现 时区/偏移量TimeZone 设置默认时区 让人恼火的夏令时 Date时区无关性 读取字符串为Date类型 SimpleDateFormat格式 ...
- Python3.9的http.client.py下的HTTPMessage类中的方法getallmatchingheaders的bug修复建议
在官方网站已经提交相关issue,不过目前看好像还没有修复.具体的bug位置为: http文件夹下的client.py文件,代码位置为:类HTTPMessage下的方法getallmatchinghe ...
- Spring Initializr中生成的mvnw是干吗的?
当我们使用Spring Initializr来创建Spring Boot工程的时候,有没有发现在工程根目录下有两个名为mvnw的文件: 从命名.图标.扩展名来猜测,这两个文件的作用应该是一样的,只是c ...
- CSS不用背景图片实现优惠券样式反圆角,凹圆角,反向半圆角,并且背景渐变
日常开发过程中,特别是商城相关应用开发过程中,时常会遇到花里胡哨的设计图,比如优惠券样式,上图: 实现思路如下: 1.先写一个外容器,实现背景色渐变: Html: 1 <div clas ...
- JavaScript中函数的定义!
JavaScript中函数的定义! 1 自定义函数(命名函数) function fun() {}; 2 函数表达式(匿名函数) var fun = function () {}; 3 利用 new ...
- 为失败设计,大量引入对SRE的理解,鲁棒性高
https://go-kratos.dev/#/ Principles 简单:不过度设计,代码平实简单 通用:通用业务开发所需要的基础库的功能 高效:提高业务迭代的效率 稳定:基础库可测试性高,覆盖率 ...
- Win+R 快速启动程序
将某个程序的可执行C:\Program Files\Oracle\VirtualBox\VirtualBox.exe 或其快捷键 放入 某个自建的快捷键集合文件夹,可以自定义命名 如 vb 将其添加到 ...
- Language Guide (proto3) | proto3 语言指南(十四)选项
Options - 选项 .proto文件中的单个声明可以使用许多 选项 进行注释.选项不会更改声明的总体含义,但可能会影响在特定上下文中处理声明的方式.可用选项的完整列表在google/protob ...
- Git实践笔记(一)
Git是什么 Git是目前世界上最先进的分布式版本控制系统. 工作原理 / 流程: Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remo ...
- Flutter--Dart基础语法(四)异步
前言 Flutter 是 Google 开源的 UI 工具包,帮助开发者通过一套代码库高效构建多平台精美应用,Flutter 开源.免费,拥有宽松的开源协议,支持移动.Web.桌面和嵌入式平台. Fl ...