题目

定义\(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. 谷歌浏览器vue.js devtools插件安装

    github官网 https://github.com/vuejs/vue-devtools#vue-devtools 插件安装地址(需FQ) https://chrome.google.com/we ...

  2. 【WiFi开发全攻略】WIFI基础知识大全

    [WiFi开发全攻略]WIFI基础知识大全 1. Wi-Fi起源 现在我们大家对Wi-Fi肯定都不陌生,无论是笔记本,手机,智能电视,都离不开Wi-Fi.目前我们一般用的都是Wi-Fi5,Wi-Fi6 ...

  3. Could not resolve type alias 'com.github.mybatis.helper.page.PageSqlInterceptor'.

    报错信息  Could not resolve type alias 'com.github.mybatis.helper.page.PageSqlInterceptor'. Cause: java. ...

  4. C C++指针面试题零碎整理

    最基础的指针如下: int a; int* p = &a; 答:p指向a的地址,&是取a的地址.*指的是指针中取内容的符号. 2.str[]和str*的区别: char str1[] ...

  5. 【Azure Batch】在中国区批处理服务(Mooncake Batch Account)上实验自动池(Auto Pool)的创建/删除

    问题描述 在Azure Batch的介绍文档中,提出了自动池的概念, 它可以在任务完成后,自动删除Pool资源,详细介绍:https://docs.azure.cn/zh-cn/batch/nodes ...

  6. 【Azure 应用服务】[App Service For Linux(Function) ] Python ModuleNotFoundError: No module named 'MySQLdb'

    问题描述 在使用Azure Function创建新的Python Function时,使用MySQLdb连接数据库时候出现 ModuleNotFoundError: No module named ' ...

  7. Java 常用类 于 StringBuffer 和 StringBuilder的使用 + String三者的异同

    1 package com.bytezero.stringclass; 2 3 import org.junit.Test; 4 5 /** 6 * 关于 StringBuffer 和 StringB ...

  8. Android APP 渗透测试---总结

    1.apk反编译得到源代码 使用编译软件 dex2gar 和 jdgui.jar 对Android APP软件进行反编译.具体步骤如下: (1)首先将APK文件后缀改为zip并解压,得到其中的clas ...

  9. better-scroll 1.13

    简单入门示例:快速使用: <template> <div class="wrapper"> <div class="content" ...

  10. 基于TLSR8359的2.4G私有协议多发一收方案解析

    一 简析 1.简介 泰凌微的2.4G私有协议芯片在市场应用十分广泛. 2.特性 无线传输距离远 功耗低,接口丰富 自带mcu功能,可实现mcu+2.4G的私有功能 二 源码解析 1.原理图 框图如下所 ...