LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#26 April 27 2014

NuclearVision
Member

Re: [Exercise] Large sums

@john it's 10539, I solved it with python a year ago, in python variables are not declared I even remember printing the 1000!, it does not overflow as easily as C and its derivatives.
edit: John I studied your code and I think it's rather summing strings than integers.
I'm not sure but here is my hypotheses:
1000! In bigint is equal to a six digits number (due to overflow); you made a string out of this number then added it to a.
So if my hypotheses is true, if you do bigint r; then print r it should be something similar to 133xxx (the solution you have which I don't remember ).

Last edited by NuclearVision (April 27 2014)

Offline

#27 April 27 2014

Ra8
Member

Re: [Exercise] Large sums

in php...

array_sum(str_split(gmp_strval(gmp_fact(1000))));

Offline

#28 April 27 2014

Ra8
Member

Re: [Exercise] Large sums

@Johnaudi

You are summing the ascii value of the digits and not the digit itself.
Change

a += r.ToString()[i];

to

a = a + r.ToString()[i] - 48;

48 is the ascci value of 0, the others are 49,50,etc...

Offline

#29 April 27 2014

NuclearVision
Member

Re: [Exercise] Large sums

@ra8 hello friend!
Don't strings sum up in c#?

Offline

#30 April 27 2014

Ra8
Member

Re: [Exercise] Large sums

NuclearVision wrote:

@ra8 hello friend!
Don't strings sum up in c#?

Those are characters that he's adding up, not strings.
check http://ideone.com/hLUqOb

Offline

#31 April 28 2014

NuclearVision
Member

Re: [Exercise] Large sums

Ok cool, thanks for helping us! now I know c# is really different from c++.

Offline

Board footer