时间限制: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. apache 服务发布多个项目,只需要更改配置文件(需要设定虚拟主机)

    http://www.php186.com/content/article/apache/24609.html http://blog.sina.com.cn/s/blog_6b689d5901013 ...

  2. JavaScript高级程序设计13.pdf

    使用hasOwnProperty()方法检测一个属性存在实例还是原形中,当属性存在对象实例中时,返回true alert(person1.hasOwnProperty("name" ...

  3. hdu 4738 Caocao's Bridges (tarjan求桥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相 ...

  4. shiro能做什么,做j2ee时候要考虑什么

    转载: http://jinnianshilongnian.iteye.com/blog/2018398,         感谢原作者 <跟我学Shiro>PDF完结版下载 博客分类: 跟 ...

  5. Apache-POI操作Excel的一些小技巧

    Apache-POI操作Excel将合并后的单元格全部填充为相同数据的一个实例. private static void fillMergedRegion(final Sheet sheet) { f ...

  6. sonarQube 管理

    sonarQube是一个管理代码质量的开放平台,它可以从七个维度检测和扫描代码质量 参考百度文库:http://wenku.baidu.com/view/cba28af9b90d6c85ed3ac67 ...

  7. SuperSocket使用demo

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using SuperSocket. ...

  8. Ubuntu 命令行下快速打开各类文件 分类: ubuntu shell 2014-11-18 20:06 210人阅读 评论(0) 收藏

    xdg-open 命令可以用来在Ubuntu下快速打开各类文件. 下面是从 manual 文档里截取的内容: 可以知道,该命令的功能是在图形界面下按照用户的平时习惯打开各类文件,甚至是链接. 这样,我 ...

  9. android 01

    安卓开源(就是免费),谷歌收购后推出,可以山寨(小米,三星都是安卓的山寨),ios不是开源(苹果应用要商用就要交钱).安卓3.0是平板,现在安卓至少是4.0以上,否则out了. 微软主要是系统和off ...

  10. linux 内核分析+使用SystemTap调试新增内核模块

    http://blog.chinaunix.net/uid/14528823/list/1.html?cid=189394