时间限制:0.25s

空间限制:4M

题目大意

给出n个数,求n1+n1*n2+n1*n2*n3+n1...n的数根,数根是一个数各个位置数字和的树根,个位数的数根为它本身。

例如,f[987]=f[9+8+7=24]=f[2+4=6]=6;


solution

对于不了解树根的,先看这样的证明

abc 是一个3位数,

abc%9=(a*100)%9+(b*10)%9+c%9

=a%9+b%9+c%9

=(a+b+c)% 9

于是直接模拟,不断取模

参考代码

 #include <stdio.h>
using namespace std;
int T, n, x;
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
int ans = , tmp = ;
for (int i = ; i < n; ++i)
{
scanf("%d", &x);
tmp = (tmp * (x % )) % ;
ans = (ans + tmp) % ;
}
if (!ans) ans = ;
printf("%d\n", ans);
}
return ;
}

SGU 118.Digital root的更多相关文章

  1. 数学 - SGU 118. Digital Root

    Digital Root Problem's Link Mean: 定义f(n)为n各位数字之和,如果n是各位数,则n个数根是f(n),否则为f(n)的数根. 现在给出n个Ai,求出A1*A2*…*A ...

  2. 快速切题 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 ...

  3. Digital root(数根)

    关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这 ...

  4. 数字根(digital root)

    来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digi ...

  5. 【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+..+ ...

  6. Sum of Digits / Digital Root

    Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...

  7. digital root问题

    问题阐述会是这样的: Given a non-negative integer num, repeatedly add all its digits until the result has only ...

  8. 1. 数字根(Digital Root)

    数字根(Digital Root)就是把一个自然数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这个一位数便是原来数字的数字根.例如: 198的数字根为9(1+9+8=18,1 ...

  9. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

随机推荐

  1. 2015第43周三memcached

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...

  2. scanf从文件中读入,printf写入到文件

    重定向方式读写文件 #include <stdio.h> #define LOCAL int main() { #ifdef LOCAL freopen("input.txt&q ...

  3. NDK安装 eclipse 不出现NDK目录问题

    android adt自带eclipse无法设置ndk路径 具体情况是 我在mac上搭建android环境 到android sdk官网下载r23版本的adt时自带的eclipse没有设置ndk路径的 ...

  4. 为什么Android没有iOS那么顺滑

    虽然很多Android手机的配置都比iPhone要高,比如大多数Andorid手机的内存都有1GB,而iPhone 4S只有512MB内存,但用过iPhone的人都知道Android手机在使用的时候总 ...

  5. [置顶] Linux 流量控制

    在如今的网络界,也许TC知道的人并不多了,这篇文章做留恋吧. 以前研究TC时记录下的讲解与配置文件. eth1:192.168.1.1,内网口  业务需求:保证正常的网页浏览,FTP,SMTP,POP ...

  6. [React] Linting React JSX with ESLint (in ES6)

    ESLint is a JavaScript linter (static analysis tool) that offers full support for ES6, JSX, and othe ...

  7. POCISO-採购创建内部订单(R12.2.3)

     採购创建内部订单(R12.2.3) --US Program:Create Internal Orders Short Name:POCISO Application:Purchasing Ex ...

  8. spring mvc DispatcherServlet详解之interceptor和filter的区别

    首先我们看一下spring mvc Interceptor的功能及实现: http://wenku.baidu.com/link?url=Mw3GaUhCRMhUFjU8iIDhObQpDcbmmRy ...

  9. iOS--为视图添加阴影

    iOS–为视图添加阴影 情况一:视图添加圆角,在添加阴影 //阴影视图 self.viewShadow = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ...

  10. C++ 进阶必备

    C++ 进阶要点(原理+熟练使用) 持续更新中 虚函数 虚继承 多继承 构造函数,拷贝构造函数,赋值构造函数,友元类,浅拷贝,深拷贝,运算符重载 class 类的基本使用,iostream获取屏幕输入 ...