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 == C,则必有d(A*B) == d(C)。
若不考虑A*B != C,则答案既是ans[x]*ans[y]*ans[d(x*y)],ans[x]为d(i) == x的个数,显然x∈[1,9]。
当考虑A*B != C时。则须要从ans[x]*ans[y]*ans[d(x*y)] - sum。
sum = sigma(n/i) , i ∈[1。n]。
int main()
{ int n,i,j,tmp; scanf("%d",&n); LL anw = 0; for(i = 1;i <= n; ++i)
{
ans[(tmp = i%9) == 0 ? 9 : tmp]++;
anw -= n/i;
} for(i = 1;i <= 9; ++i)
for(j = 1;j <= 9; ++j)
anw += ans[i]*ans[j]*ans[(tmp = (i*j)%9) == 0 ? 9 : tmp]; printf("%I64d\n",anw); return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
CodeForces 10C. Digital Root的更多相关文章
- codeforces 10C Digital Root(非原创)
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and ...
- 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 ...
- 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 ...
随机推荐
- dtach-linux-分离功能-小工具 - 点点滴滴 Linux | 点点滴滴 Linux
dtach-linux-分离功能-小工具 - 点点滴滴 Linux | 点点滴滴 Linux dtach-linux-分离功能-小工具 2013年05月20日 ⁄ Linux工具 ⁄ 共 1775字 ...
- latex表格线的颜色设置(边框添加颜色)
添加了如下包:边框颜色要用到booktabs, colortbl, 包,下面代码里有一个自定义的颜色tabcolor \usepackage{ctexcap} \usepackage{graphicx ...
- jquery实现菜单功能(单击展开或者关闭)-一般应用于后台
<!doctype html> <html> <head> <meta charset="gb2312"> <title> ...
- 自己动手写处理器之第一阶段(2)——MIPS指令集架构的演变
将陆续上传本人写的新书<自己动手写处理器>(尚未出版),今天是第三篇.我尽量每周四篇 MIPS指令集架构自上世纪80年代出现后.一直在进行着更新换代,从最初的MIPS I到MIPS V,发 ...
- 开源mp3播放器--madplay 编译和移植 简记
madplay是一款开源的mp3播放器. http://madplay.sourcearchive.com/ 下面简单记录一下madplay的编译与移植到ARM开发板上的过程 一.编译x86版本的ma ...
- Oschat IM 开源即时通讯项目介绍 - FengJ的个人页面 - 开源中国社区
Oschat IM 开源即时通讯项目介绍 - FengJ的个人页面 - 开源中国社区 Oschat IM 开源即时通讯项目介绍 255人收藏此文章, 我要收藏 发表于5天前(2013-08-28 ...
- Object.Instantiate 实例
static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object ...
- 在后台运行erlang;在需要时连回交互模式
* 1. 启动后台运行的erlang环境 按以下命令: erl -detached -name a@127.0.0.1 注意,-name的值必须是xxxx@ip的形式.其中xxxx是英文名,ip必须是 ...
- python(abi) RPM DEB Download
python(abi) RPM DEB Download python(abi) RPM DEB Download
- UVA 10140 - Prime Distance(数论)
10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...