ACM (UVa) : 10220


I Love Big Numbers!

Data type:
Integer

Algorithm:
String-Integer Manipulation [Big integer in Array, Under Common Categories]

Critical parts:
// Declare a sufficient sized array, it’s would be 5000
// Each time Initialize the array with 1, to avoid garbage value.
// Input will be terminated by EOF (End of File)

Critical Input:
1000
999
998
500

Critical Output:
10539
10539
10287
4599

#include

int main ()
{
long N, I, Carry, LenA, Sum;

while ( scanf (“%ld”, &N) != EOF ){

long A [5000] = {1};
LenA = 1;

while ( N ) {

Carry = I = 0;

while ( I < LenA ) { Carry = ( A [I] *N ) + Carry; A [I++] = Carry % 10; Carry /= 10; } while ( Carry){ A [I++] = Carry % 10; Carry /= 10; } LenA = I; N--; } LenA--; Sum = 0; while ( LenA ) Sum += A [LenA--]; printf("%ld\n", Sum); } return 0; } [/sourcecode]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s