I am looking for help with some code I have written for Project Euler Problem 148.
The problem is as follows:
Find the number of entries which are not divisible by 7 in the first one billion rows of Pascal's triangle.
I am aware that this specific method will not work as it will - when ran with 1000000000 - result in an overflow error.
Regardless, I am curious why this code does not work:
I use the expression ((math.factorial(r))/((math.factorial(t))*(math.factorial((r-t))))) to find the value of the term at the given row and term, as shown by the formula:
When numrows == 7, the script should print 0, which it does.
When numrows == 100, the script should print 2361, but my code prints 3139.
The code is as follows:
import math
numrows = 100
count = 0
for r in range(numrows):
for t in range(r):
if not (((math.factorial(r))/((math.factorial(t))*(math.factorial((r-t))))) % 7 == 0):
count += 1
print(count)

tgo from 0 to r, and you only go up to (r-1). This way, you miss one value on each row (and as they all are1, they should be counted.)