Why getting WA in Uva problem 10220 - I Love Big Numbers?

I was solving the problem 10220 - I Love Big Numbers! on Uva. ( http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1161 )
My solution is given below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a[1000]; //array will have the capacity to store 200 digits.

    int n,i,j,temp,m,x;

    while(cin>>n)
    {
        a[0]=1;  //initializes array with only 1 digit, the digit 1.

        m=1;    // initializes digit counter

        temp = 0; //Initializes carry variable to 0.

        for(i=1;i<=n;i++)
        {
            for(j=0;j<m;j++)
            {
                x = a[j]*i+temp; //x contains the digit by digit product

                a[j]=x%10; //Contains the digit to store in position j

                temp = x/10; //Contains the carry value that will be stored on later indexes
            }

            while(temp>0) //while loop that will store the carry value on array.
            {
                a[m]=temp%10;

                temp = temp/10;

                m++; // increments digit counter
            }
        }

        int sum=0;

        for(i=m-1; i>=0; i--) //printing answer
            sum+=a[i];

        printf("%d\n",sum);
    }

    return 0;

 }
Last edited on
> int a[1000]; //array will have the capacity to store 200 digits.
I guess that an array of 1000 elements would hold 1000 digits. However, considering the input limits, ¿how many digits do you need?
Topic archived. No new replies allowed.