http://acm.hdu.edu.cn/showproblem.php?pid=2576
推导公式,,,还要学下同余模里的除法怎么处理。。。
设数列{an},a1=1, a2=1+2, a3=1+2+3,...,an=1+2+...+n
易知an的通项公式an=n*(n+1)/2=(1/2)*(n^2+n)
记Sn为{an}前n项之和
所以,
原式=Sn-1
=(1/2)*[(1+2+3+...+n)+(1^2+2^2+3^2+...+n^2)]-1
=(1/2)*[(1/2)*n*(n+1)+(1/6)*n*(n+1)*(2n+1)]-1
=(1/12)*n*(n+1)*(3+2n+1)-1
=(1/6)*n*(n+1)*(n+2)-1
#include<stdio.h> int main() { __int64 t,n,sum,a,b,M=20090524; scanf("%I64d",&t); while(t--) { scanf("%I64d",&n); if(n==1) { printf("1 "); continue; } else { a=n+1;b=n+2; if(n%2==0) n/=2; else a/=2; if(n%3==0) n/=3; else if(a%3==0) a/=3; else if(b%3==0) b/=3; sum=(((n%M)*a)%M*b)%M; } printf("%I64d ",sum); } return 0; }