题目

定义\(d(x)\)为\(x\)的数位和嵌套,直至\(0\leq d(x)<10\)

询问在\([1\sim n]\)中有多少个三元组\((a,b,c)\)满足

\[ab\neq c,d(d(a)\cdot d(b))=d(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的更多相关文章

  1. Digital root(数根)

    关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这 ...

  2. 数字根(digital root)

    来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digi ...

  3. 【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+..+ ...

  4. Sum of Digits / Digital Root

    Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...

  5. digital root问题

    问题阐述会是这样的: Given a non-negative integer num, repeatedly add all its digits until the result has only ...

  6. 1. 数字根(Digital Root)

    数字根(Digital Root)就是把一个自然数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这个一位数便是原来数字的数字根.例如: 198的数字根为9(1+9+8=18,1 ...

  7. 快速切题 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 ...

  8. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

  9. 数学 - SGU 118. Digital Root

    Digital Root Problem's Link Mean: 定义f(n)为n各位数字之和,如果n是各位数,则n个数根是f(n),否则为f(n)的数根. 现在给出n个Ai,求出A1*A2*…*A ...

  10. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

随机推荐

  1. 学习go语言编程之安全编程

    数据加密 对称加密 采用单密钥的加密算法,称为对称加密. 常见的单密钥加密算法有DES.AES.RC4等. 在对称加密中,私钥不能暴露,否则在算法公开的情况下,数据等同于明文. 非对称加密 采用双密钥 ...

  2. 在SpringBoot中实践AOP编程

    具体实践 Spring AOP是Spring框架中一个支持实现面向切面编程的模块,由于Spring Boot已经把Spring框架组合得非常好用,所以在基于Spring Boot框架的项目中实现AOP ...

  3. Go语言实现记账本

    使用面向过程思想实现 package main import ( "fmt" ) func main(){ key := "" //设置初始金额 sum := ...

  4. ZYNQ 裸机模式下修改默认uart端口

    ## 背景 调试ZYNQ 裸机code, 调用 printf()后在UART端口无法看到打印信息输出,查看原理图后发现,板子用的UART 1作为默认串口调试接口,UART 0分配给了RS485使用,因 ...

  5. webservice之jersey简单实用

    前言 项目中更需要使用到webservice,具体的是使用jersey.那么首先需要了解jersey和webservice的关系,捋顺webservice框架的各种实现,通过查阅相关博客,我个人总结w ...

  6. 【Azure 媒体服务】Azure Media Service上传的视频资产,如何保证在Transfer编码后音频文件和视频文件不分成两个文件?保持在一个可以直接播放的MP4文件中呢?

    问题描述 Azure Media Service上传的视频资产,如何保证在Transfer编码后音频文件和视频文件不分成两个文件?保持在一个可以直接播放的MP4文件中呢? 问题解答 Azure Med ...

  7. 【Azure 应用服务】在创建Web App Service的时候,选Linux系统后无法使用Mysql in App

    问题描述 如图上,是App Services在Windows环境中,系统自带了MySQL In App功能.而在,Linux环境中,没有发现Mysql in App功能,是不是无法在Linux中使用呢 ...

  8. C++ 总结大项目:机房预约系统项目(数据结构 +指针+class(类操作)+面向对象三大特性[继承+多态+封装]+文件(读,写,保存,重写,重建,清空)+string(比较,截取,追加),+容器多个操作,嵌套+算法+清空数据)

    1 /** 2 * 项目名称:机房预约系统 3 * 时 间:2021-08 4 * 作 者:Bytezero!·zhenglei 5 * 6 * 系统简介: 7 * 学校有几个规格不同的机房,由于使用 ...

  9. MongoDB可视化compass 连接数据库失败Invalid UTF-8 string in BSON document

    An error occurred while loading navigation: Invalid UTF-8 string in BSON document 出现这个问题建议降低compass版 ...

  10. Metasploitable3 渗透测试

    1.信息手机阶段 信息收集经常使用的软件 功能也比较强大的Nmap Nmap nmap -p- -sS -sV -n -v --reason --open -oX demon.xml 192.168. ...