sgu 118 Digital Root
来源:互联网 发布:c语言return0写在哪 编辑:程序博客网 时间:2024/04/30 11:08
118. Digital Root
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
Let f(n) be a sum of digits for positive integern. If f(n) is one-digit number then it is a digital root for n and otherwise digital root of n is equal to digital root of f(n). For example, digital root of987 is 6. Your task is to find digital root for expression A1*A2*…*AN + A1*A2*…*AN-1 + … + A1*A2+ A1.
Input
Input file consists of few test cases. There is K (1<=K<=5) in the first line of input. Each test case is a line. Positive integer numberN is written on the first place of test case (N<=1000). After it there areN positive integer numbers (sequence A). Each of this numbers is non-negative and not more than109.
Output
Write one line for every test case. On each line write digital root for given expression.
Sample Input
13 2 3 4
Sample Output
5题目不是很难,很容易知道结论就是模9但是要注意如果整除9的话答案是9不是0哦代码:#include<iostream>#include<cstring>#include<cstdio>#include<set>#include<algorithm>#include<vector>#include<cstdlib>#define inf 0xfffffff#define CLR(a,b) memset((a),(b),sizeof((a)))using namespace std;int const nMax = 40000;typedef long long LL;typedef pair<LL,LL> pij;LL k,n,a,ans,b;int main(){ scanf("%lld",&k); while(k--){ scanf("%lld",&n); ans=0; b=1; for(int i=0;i<n;i++){ scanf("%lld",&a); a%=9; b*=a; b%=9; ans+=b; ans%=9; } if(ans==0)ans=9; printf("%lld\n",ans); } return 0;}
- sgu 118 Digital Root
- SGU 118 Digital Root
- SGU 118 Digital Root(数论)
- [SGU]118. Digital Root
- 【SGU】118. Digital Root
- SGU 118. Digital Root 找规律+模拟
- Digital Root
- digital root
- digital root
- Digital Root 算法
- Digital Root----code forces
- HDU 4351 - Digital root
- hdu4351 Digital root
- Digital Root的问题
- Vasya and Digital Root
- POJ 1519 digital root
- sgu118:Digital root
- 118. Digital Root
- 第 10 章linux进程间通信 1. 进程间通信概述
- 浏览器是怎么工作的(前端必读)
- SQL Server 2005 Express sa登录失败系列问题解决
- 3D ICE AGE笑爆全场、笑足全程
- Linux Socket通信 C/S模型(有问题,求分析)
- sgu 118 Digital Root
- hdu 4450 Draw Something
- 使用ProGuard使你android代码保持混淆
- 五只猴子分桃,算法&面试
- xcode意外崩溃
- MP4Box: fragmentation, segmentation, splitting and interleaving
- 贪心算法::启发式搜索
- Linux网络编程一步一步学-设置非阻塞方式
- 刷机大师探秘