The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
#define N 1000
#define M 3
void series(int x,int temp[])
{
int i,j,d;
for (i = 0; i < x; i++)
{
d = 0;
for (j = 0; j < M; j++)
{
temp[j] = temp[j] * x+d;
d = temp[j]/10000;
temp[j] = temp[j] % 10000;
}
}
}
void sum(int num[], int temp[])
{
for (int i = 0,d = 0; i < M; i++)
{
num[i]+=temp[i]+d;
temp[i] = 0;
d = num[i]/10000;
num[i] = num[i] % 10000;
}
temp[0] = 1;
}
int main()
{
clock_t ts,te;
ts=clock();
int num[M] = {0},temp[M] = {1};
int i;
for (i = 1; i < N; i++)
{
series(i,temp);
sum(num,temp);
}
num[2] = num[2]%100;
printf("\nanswer ");
for (i = M-1; i>=0; i--)
{
printf("%d",num[i]);
}
te=clock();
printf("\ntime difference: %ds\n",(te-ts)/CLOCKS_PER_SEC);
getchar();
return 0;
}