#计数#CF10C Digital Root
题目
定义\(d(x)\)为\(x\)的数位和嵌套,直至\(0\leq d(x)<10\)
询问在\([1\sim n]\)中有多少个三元组\((a,b,c)\)满足
\]
分析
\(d(x)=x \bmod 9\),那么\(d(d(a)\cdot d(b))=a*b\bmod 9=c\bmod 9\)
首先\(ab\neq c\)不容易处理,考虑容斥
也就是用\(a*b\bmod 9=c\bmod 9\)的方案数减去\(a*b=c\)的方案数
首先第一部分可以统计\([1\sim n]\)中余数为\([0\sim 8]\)的个数,那么两重循环就能解决
后面这坨就是相当于对于每个\(c\)求\(c\)的约数个数,因为确定\(a,c\),那么\(b\)也是可以确定的,那也就是求\([1\sim n]\)的约数个数和,也就是$$\sum_{i=1}^n\lfloor\frac{n}{i}\rfloor$$
所以\(O(n)\)解决
代码
#include <cstdio>
#define rr register
using namespace std;
typedef long long lll;
lll n,ans,d[9];
signed main(){
scanf("%lld",&n);
for (rr int i=1;i<=n;++i) ans-=n/i,++d[i%9];
for (rr int i=0;i<9;++i)
for (rr int j=0;j<9;++j)
ans+=d[i]*d[j]*d[i*j%9];
return !printf("%lld",ans);
}
#计数#CF10C Digital Root的更多相关文章
- Digital root(数根)
关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这 ...
- 数字根(digital root)
来源:LeetCode 258 Add Dights Question:Given a non-negative integer num , repeatedly add all its digi ...
- 【HDOJ】4351 Digital root
digital root = n==0 ? 0 : n%9==0 ? 9:n%9;可以简单证明一下n = a0*n^0 + a1*n^1 + ... + ak * n^kn%9 = a0+a1+..+ ...
- Sum of Digits / Digital Root
Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...
- digital root问题
问题阐述会是这样的: Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- 1. 数字根(Digital Root)
数字根(Digital Root)就是把一个自然数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这个一位数便是原来数字的数字根.例如: 198的数字根为9(1+9+8=18,1 ...
- 快速切题 sgu118. Digital Root 秦九韶公式
118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...
- Codeforces Beta Round #10 C. Digital Root 数学
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...
- 数学 - SGU 118. Digital Root
Digital Root Problem's Link Mean: 定义f(n)为n各位数字之和,如果n是各位数,则n个数根是f(n),否则为f(n)的数根. 现在给出n个Ai,求出A1*A2*…*A ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
随机推荐
- r0capture 原理分析
r0capture 是比较好用的抓包工具 仅限安卓平台,测试安卓7.8.9.10.11.12 可用 : 无视所有证书校验或绑定,不用考虑任何证书的事情: 通杀TCP/IP四层模型中的应用层中的全部协议 ...
- Linux驱动开发笔记(一):helloworld驱动源码编写、makefile编写以及驱动编译基本流程
前言 基于linux的驱动开发学习笔记,本篇是描述了一个字符驱动的基础开发流程,以便做嵌入式开发多年的应用或者系统学习驱动开发. 笔者自身情况 笔者拥有硬件基础,单片机软硬基础,linux ...
- itertools.chain.from_iterable()将嵌套列表合并成一个
from itertools import chain a = [[1,2],[3,4]] print(chain.from_iterable(a)) # [1,2,3,4]
- pip相关知识
正常安装语法 # 安装单个 pip install some-package # 安装指定版本 pip install some-package==版本号 # 查看当前模块版本号 pip instal ...
- CoaXPress 协议的CRC及其具体实现
CoaXPress CRC 在CXP协议中,CRC用在stream packet和control packet中,用于指示数据是否错误,如果是control packet, device发现CRC错误 ...
- 【Azure 存储服务】Blob中数据通过Stream Analytics导出到SQL/Cosmos DB
问题描述 Json格式的数据目前是存储在Azure Blob中,如何将这些数据Load到Sql DB和CosmosDB中呢? 测试方案 使用Azure流分析服务(Stream Analytics)功能 ...
- 十四: Mysql数据结构选择的合理性
Mysql数据结构选择的合理性 从MySQL的角度讲,不得不考虑一个现实问题就是磁盘I/O. 如果我们能让索引的数据结构尽量减少硬盘的I/O操作,所消耗的时间也就越小.可以说,磁盘的I/O操作次数对索 ...
- 十: SQL执行流程
SQL执行流程 1. MySQL 中的 SQL执行流程 MySQL的查询流程: 1.1 查询缓存 Server 如果在查询缓存中发现了这条 SQL 语句,就会直接将结果返回给客户端:如果没 有,就进入 ...
- python用matplotlib或boxplot作图的时候,中文标注无法正常显示,乱码为小方框的解决办法
第一种 import matplotlib.pyplot as plt plt.rc("font",family="SimHei",size="22& ...
- 使用Kubernetes搭建带有ik分词的Elasticsearch集群
创建好带有Ik分词的es镜像,并上传到镜像仓库中,创建镜像可参考链接中的文档 https://www.cnblogs.com/hi-lijq/p/16895206.html 编写es_cluster- ...