时间限制: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. 【转】Android编译系统详解(三)——编译流程详解

    原文网址:http://www.cloudchou.com/android/post-276.html 本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 1.概述 编译Androi ...

  2. 【转】 std list/vector sort 排序

    [转自]http://blog.csdn.net/marising/article/details/4567531 网上江湖郎中和蒙古大夫很多,因此,此类帖子也很多.关于排序,我还真没研究过,看了江湖 ...

  3. HDOJ(HDU) 2523 SORT AGAIN(推导排序、、)

    Problem Description 给你N个整数,x1,x2-xn,任取两个整数组合得到|xi-xj|,(0 < i,j<=N,i!=j). 现在请你计算第K大的组合数是哪个(一个组合 ...

  4. [git] git 的基本认知

    版本管理 ( Version Control ) 版本管理系统是一个记录文件变更的系统,让你在一段时间后可以恢复指定版本的文件.版本管理系统大致可分为三类:独立的本地版本管理系统.中心化版本管理系统. ...

  5. SIP协议错误代码大全

    100 Trying 说明caller正在呼叫,但还没联系上callee. 180 Ringing 说明callee已经被联系上,callee的铃正在响.收到这个信息后,等待200 OK 181 Ca ...

  6. asterisk帮助与国内论坛

    http://www.in2eps.com/fo-abnf/tk-fo-abnf-http.html www.asteriskguru.com/ http://www.voip-info.org/ h ...

  7. 趣解curl

    Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1) 二话不说,先从这里开始吧! $ curl http://www.linuxidc.com 回车之后,www.linuxid ...

  8. 一句话菜刀获取ip详细信息

    <?php $ip="你要查的ip"; $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip ...

  9. 异步加载图片到GridView上,防止OOM

    图片资源: private int fore[]; private int back[]; fore = new int[]{R.drawable.a0, R.drawable.a1, R.drawa ...

  10. 有关Transaction not successfully started问题解决的方法

    我的项目配置:struts2+hibernate3.3+spring3.2.5 主要问题:在进行更新和提交操作时出现下面异常 org.springframework.transaction.Trans ...