Where is my formula false??

169 Views Asked by At

I wrote a formula that returned how many numbers in a given row of pascals triangle are divisible by a given prime.

This formula was created to answer https://projecteuler.net/problem=148.

I was able to determine that my formula works (using the number 7) against the first 82,000 rows of Pascal's Triangle, but I am still unable to plug in the right answer.

I think that somewhere between rows 82,000 and 1 billion my formula goes wrong, if anyone can help me find out where (what row number), or if anyone can help me fix the formula , i'd greatly appreciate it.

(Extra / Useless info: When looking into this I noticed that if you black out all the numbers divisible by the given prime in the triangle, it turns into Sierpinski's triangle, using that pattern i was able to create the formula)

r = row number

p = prime number

if r < p return 0

c = p^floor(log(r) / log(p)) (largest exponent of p that does not exceed r)

a = r % c

b = floor(r / c)

f(r,p) = b(c-a-1) + (f(a,p)*(b+1))

1

There are 1 best solutions below

0
On BEST ANSWER

Good news, there was nothing wrong with this after all, I finally got the right answer, I was just looking at the wrong information.