Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating total of a row in pascal triangle?

I've been trying to calculate total of 1500th row in pascal triangle in c++.

I tried more than 6 different code snippets from all over the web.

Some of them crashed before 10th row, some gone crazy etc.

How can one achieve calculating total of numbers in 1500th row in pascal triangle.

I think there must be a formula to find a row without iterating over each row, because iterations causing program to crash.

like image 295
Ahmet Yildirim Avatar asked Feb 20 '23 00:02

Ahmet Yildirim


1 Answers

The sum of the numbers in any row is equal to 2 ^ n where n is the row (starting at 0). So in your case, it would just be 1 << 1499.

enter image description here

Your answer is the following:

17537331055217019373813793980140428996762007940165414412037899012395481925281661101828540443292484630826575203397718758699647274470734979877085519459002350423944978242664548632243401355791731473268341092170069314725677729132473171262691809694657480322332526275875721167754624586680565177898054854942790337156977105108828923716313380366502376637658596066837351781686391648520996613526331666834254976000087526677764529440217091269193357761841856604274688

like image 119
arshajii Avatar answered Feb 27 '23 13:02

arshajii