#计数#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 ...
随机推荐
- win32 - 以编程方式访问远程计算机上的文件
第一步,在一台计算机上将某个驱动器或者某个文件夹设为sharing模式.这是我们需要访问的共享文件夹.(不需要设置everyone权限) 第二步,我们需要为两台在同一domain下的计算机上建立连接. ...
- centos7.5 hadoop NAT 静态IP网络环境搭建
1 设置 VMware 网络环境 1. 选择VMNet8 并将子网IP 修改为 192.168.10.0,保证集群ip都在这个网段下 2. 选择NAT 设置,配置NAT的网关为 192.168.10. ...
- IntelliJ IDE使用指南
下载IDEA 注释模板 #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}; ...
- WSL2镜像文件压缩
WSL2的镜像文件(*.vhdx)支持自动扩容,但是一般不会自动缩容.一旦某次存放过大文件以后,即使后续删除,镜像文件体积仍然不会缩小,导致大量磁盘空间浪费.因此,可以定期对镜像文件进行手动压缩. 镜 ...
- ASP.NET 通过拦截器记录错误日志
前言 主要是记录一下实现的错误日志拦截,可以在拦截器里面控制返回的信息,把错误信息处理后返回给请求端. 代码实战 拦截器 /// <summary> /// 接口异常捕捉过滤器 /// & ...
- 【Azure Spring Cloud】使用azure-spring-boot-starter-storage来上传文件报错: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known
问题描述 使用 azure-spring-boot-starter-storage 来上传文件到 Storage Blob中,并把应用部署到Azure 中国区的Spring Cloud服务后,调用上传 ...
- 13 Codeforces Round 886 (Div. 4)G. The Morning Star(简单容斥)
G. The Morning Star 思路:用map记录x,y,以及y-x.y+x 从前往后统计一遍答案即可 公式\(ans+=cnt[x]+cnt[y]-2 * cnt[x,y]+cnt[y+x] ...
- [青少年CTF训练平台]web部分题解(已完结!)
文章管理系统 首先打开环境(>ω<。人)ZZz♪♪ 既然要做题,就要做全面了,图上说了,既然有假flag我就先找出来: 假flag: 打开vmware,使用sqlmap进行处理: sqlm ...
- 将本地文件上传到github仓库
将本地文件上传到github空仓库 本地使用git上传文件: 第一步:在需要的文件夹(文件夹里已经放了需要提交的内容)右击git bash,输入git init 第二步:将本地文件上传到本地git仓库 ...
- Ubuntu 与Windows 之间搭建共享文件夹
工作中经常需要搭建Linux环境用于测试以及其他开发需求,办公电脑通常是Windows 系统,为便于让文件在两个系统之间传输,可以采取共享文件的方式实现: 1.安装samba 服务: sudo apt ...