为什么会接触到这个数学知识?
还得从一个OJ题目说起。。。。。。
Problem K
Description
FunnyAC likes mathematics very much. He thinks mathematics is very funny and beautiful.When he solved a math problem he would be very happy just like getting accepted in ACM.Recently, he find a very strange problem.Everyone know that the sum of sequence from 1 to n is n*(n + 1)/2. But now if we create a sequence which consists of the sum of sequence from 1 to n. The new sequence is 1, 1+ 2, 1+2+3, …. 1+2+…+n. Now the problem is that what is the sum of the sequence from1 to 1+2+…+n .Is it very simple? I think you can solve it. Good luck!
Input
The first line contain an integer T .Then T cases followed. Each case contain an integer n (1 <= n <= 10000000).
Output
For each case,output the sum of first n items in the new sequence. Because the sum is very larger, so output sum % 20090524.
这个题如果使用递归直接算的话,数据绝对会爆掉。。。。。。。
但是,可以自己推出公式 Sn = n(n+1)(n+2)/6;
然而数据依然爆掉。。。。。。
只能
同余与模算术在数学问题求解中的应用

本文介绍了如何利用同余与模算术解决一道数学题目,该题目涉及序列求和的问题。通过数学公式推导和模运算的应用,避免了递归计算导致的数据溢出,最终成功解决问题。
最低0.47元/天 解锁文章
81

被折叠的 条评论
为什么被折叠?



