时间限制: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. 通过超链接打开App应用

    URL schemes, 通过超链接打开App应用 var mobileAppInstall = (function () { var ua = navigator.userAgent, loadIf ...

  2. 【转】android4.1.1系统编译全过程

    原文网址:http://blog.csdn.net/hudan2714/article/details/7926924 一.编译环境: 首先介绍编译中使用的工具: 虚拟机:    vmare 9 下载 ...

  3. 转-----实现基本的Ajax和Json请求

    前面已经封装好了一个方法ajax(),通过这个方法可以实现Ajax请求,接下来就是给出 例程来测试这个方法和实现简单的功能.   视图的部分代码如下: 1 2 3 4 5 6 7 8 9 <bo ...

  4. web.xml 详解contextConfigLocation 转

    spring的应用初始化流程一直没有搞明白,刚刚又碰到了相关的问题.决定得好好看看这个流程.我们在开发spring的项目当中基本上都会在web.xml通过: <context-param> ...

  5. iOS设备隐藏StateBar

    //隐藏StateBar - (BOOL)prefersStatusBarHidden {     returnYES; }

  6. [LeetCode] Largest Rectangle in Histogram 解题思路

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. hdoj 2199 Can you solve this equation?【浮点型数据二分】

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. SQL string类型的数据按int类型排序 分类: SQL Server 2014-12-08 16:56 393人阅读 评论(0) 收藏

    说明: 我在做wms进销存软件时,发现一个问题:一张入库单(T_OutIn_BoxTop),入库扫描时要分成多箱,箱号(BoxTop_No)可以是数字也可以是字符串,所以箱号只能是字符串类型的,问题来 ...

  9. leetcode-WordLadder

    Word Ladder Total Accepted: 10243 Total Submissions: 58160My Submissions Given two words (start and  ...

  10. [React] React Fundamentals: with-addons - ReactLink

    It can be tedious to type out all the boilerplate needed to get the DOM and states in React to synch ...