The problem with skyscraper and eggs is not Newton's binomial?

In fact, he is the most. But first things first.

### Statement of the problem

I master the python, I solve everything on Codewars. Faced with a known problem about skyscraper and eggs. The only difference is that the original data - not 100 floors and 2 eggs, but a little more.

Given: N eggs, M attempts to throw them, an endless skyscraper.

Identify: the maximum floor from which you can throw an egg without breaking it. Eggs are spherical in vacuum and, if one of them did not break, falling, for example, from the 99th floor, then the rest will also withstand a drop from all floors less than one hundred.

0 <= N, M <= 20000.

The run time of two dozen tests is 12 seconds.

Triangle of Pascal , so it is officially called. Infinite table of binomial coefficients. So the answer to the problem with N eggs and M throws is the sum of the first N coefficients in the expansion of the Newton binomial of the Mth power, except for the zero one.

An arbitrary binomial coefficient can be calculated through the factorials of the line number and the coefficient number in the line: bk = m! /(N! * (M-n!)). But the most pleasant - you can consistently calculate the numbers in a row, knowing its number and zero coefficient (always one): bk[n] = bk[n-1]* (m - n + 1) /n. At each step the numerator decreases by one, and the denominator increases. And the laconic final solution looks like this:

def height (n, m):

h, bk = ? 1 # height and zero binomial coefficient

for i in range (? n + 1):

bk = bk * m //i

h + = t

m- = 1

return h

33 ms. on the calculation of f (947? 10000)! This solution can also be optimized, although it works well in the specified ranges. If n lies in the second half of the triangle, then you can invert it to m-n, calculate the sum of the first n coefficients and subtract it from 2 ^ m-2. If n is close to the middle and m is odd, then the calculations can also be shortened: the sum of the first half of the line will be 2 ^ (m-1) -? the last factor in the first half can be calculated through the factorials, its number is (m-1) /? and then either continue to add coefficients, if n in the right half of the triangle, or take away, if in the left. If m is even, then you can not count half the line, but you can find the sum of the first m /2 + 1 coefficients, calculating the average through factorials and adding half of it to 2 ^ (m-1) -1. On the input data in the vicinity of 10 ^ 6 this greatly reduces the execution time.

Even after a successful decision, I began to look for someone else's research on this issue, but found only the same thing, with interviews, with only two eggs, and this is not sports. The Internet will be incomplete without my decision, I decided, and that's it.

It may be interesting

This publication has no comments.

#### weber

Author**18-09-2018, 18:30**

Publication Date
#### Mathematics / Python

Category- Comments: 0
- Views: 297

Comments

There is a very weak knowledge in people about the astrology and spiritual stuff even it was well known by everyone in ancient times and it was the secret behind their happy life. Today is the time, when we lost our faith on spiritual science and we became addict of modern science technology.

Knowledge is very important to do any ritual properly but it is very hard to find a true knowledge about tantra, vashikaran, healing etc but thanks to avijeet aacharya who is supporting people by his free article like you and spreading the knowledge to needy people.

I seen your page and it look so interesting and i am thankful to you for spreading knowledge by this portal. if someone wants to learn about different types of powerful vashikaran mantra for boyfriend so read avijeet aacharya pages on his portal and find interesting topics and updates.

Knowledge is very important to do any ritual properly but it is very hard to find a true knowledge about tantra, vashikaran, healing etc but thanks to avijeet aacharya who is supporting people by his free article like you and spreading the knowledge to needy people.

I seen your page and it look so interesting and i am thankful to you for spreading knowledge by this portal. if someone wants to learn about different types of powerful vashikaran mantra for boyfriend so read avijeet aacharya pages on his portal and find interesting topics and updates.

Welcome in the Top Class Escorts in Delhi. Are you instant going on google and doing searches for Delhi Escorts? Then Your Search is now Over Here. Our Escorts in Delhi is ready to make your glorious mood for Call Girls in Delhi.

[hide]Call Girl in Delhi[/http://escortservicesinnewdelhi.launchrock.com/] | [hide]Escort Services in New Delhi[/https://telegra.ph/Call-Girls-in-Delhi-7428151367-Call-Girls-Services-in

-Mahipalpur-01-15] | [hide]Call Girls Services in Mahipalpur[/https://escortservicesinnewdelhi.mystrikingly.com/] | [hide]Sex Services in Paharganj[/http://www.geocities.ws/natashasingh76/index.html]

[hide]Call Girl in Delhi[/http://escortservicesinnewdelhi.launchrock.com/] | [hide]Escort Services in New Delhi[/https://telegra.ph/Call-Girls-in-Delhi-7428151367-Call-Girls-Services-in

-Mahipalpur-01-15] | [hide]Call Girls Services in Mahipalpur[/https://escortservicesinnewdelhi.mystrikingly.com/] | [hide]Sex Services in Paharganj[/http://www.geocities.ws/natashasingh76/index.html]

Great article it is useful and some new ideas after reading this article it is useful and a lot of new things and getting a lot of writing. https://www.dawateislami.net/about-us