Codeforces 10C Digital Root 法冠军】的更多相关文章

主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<string> #include<stdlib.h> #include<algorithm> using nam…
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a…
乞讨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 = si…
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equat…
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(void) //Codeforces Round #…
关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这个一位数便是原来数字的数字根.适用范围为正整数和零.例如:65536,6+5+5+3+6=25,2+5=7,故数根为7. 二.性质 1. 任何数加减9的数字根还是它本身. 2. 9乘任何数字的数字根都是9. 3. 数字根的三则运算 (1). 两数之和的数字根等于这两个数的数字根的和数字根      …
来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digits until the result has only one digit. For example: Given  num =  , the process is like:   + =  ,   + =  . Since    has only one digit, return it. Fo…
digital root = n==0 ? 0 : n%9==0 ? 9:n%9;可以简单证明一下n = a0*n^0 + a1*n^1 + ... + ak * n^kn%9 = a0+a1+..+ak然后,数学归纳易知结论是正确的.因此9个状态就够了,表示%9的结果.这里需要特殊处理0, 表示状态为0. /* 4351 */ #include <iostream> #include <sstream> #include <string> #include <m…
Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has two digits, continue reducing in this w…
问题阐述会是这样的: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up:Could you do it…