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 ...
随机推荐
- bootstrap css选择不同的宽度
刚开始使用bootstrap css开源项目.遇到一个问题,默认的input 宽度太大,需要找小一点的. 其实只需要在input tag中选用预定义的较小的宽度即可.比如: <input typ ...
- 2015年十大热门Android开源新项目
2015年十大热门Android开源新项目 2015 即将结束,又到了大家喜闻乐见的年终盘点时刻啦,今天给大家盘点一下 2015 年 Android 开发领域新出现的 10 大热门开源项目.数据来自于 ...
- OCP读书笔记(1) - Oracle核心概念和工具
ohasdoracle high available service daemon OEMweb -- Database Control资料库 -- sysman Starting Oracle Re ...
- cocos2d-x2.2.5 + cocos2d-x3.2鸟跳便宜源代码“开源”
尊重开发人员的劳动成果,转载请注明From郝萌主 游戏简单介绍: 贱鸟跳跳,贱贱的小鸟这次遇上大问题了.被它整蛊过的同类都在找它的麻烦,如今我们赶紧到游戏中帮帮它吧!左右手互撸,合理操控.获得高分,打 ...
- Ubuntu 8.04下安装DB2方法
參考文献: How-to: Ubuntu 7.10 Server x86 32-bit and DB2 Express-C v9.5 DB2 v9.7 Infomation Center 场景:在IB ...
- java 参数传递
由一个问题来引入参数传递的问题 public static void main(String[] args) { int x=1; int[] y =new int[10]; m(x,y); Syst ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- POJ 3286 How many 0's?
题目大意: 计算[m,n]之间全部数字有多少个零. 解题思路: 能够用[0,m)之间和[0,n]之间有多少个零然后作差. 规律是计算全部位置在到当前数时有多少个零. 以下是代码: #include ...
- 安装pygame
pygame的安装 我们首先要去到:http://www.pygame.org/download.shtml 下载我们所需要的软件包: 我选择的是:pygame-1.9.2a0.win32-py3.2 ...
- OCP读书笔记(18) - 空间管理
OLTP 表压缩 压缩始终是非常占用CPU的过程,并且需要花费一定时间,通常,如果压缩数据,则数据必须解压缩后才能使用.虽然此要求在数据仓库环境中是可以接受的但在OLTP环境中可能无法接受 现在,在O ...