We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #148: Exploring Pascal's triangle.
Project Euler #148: Exploring Pascal's triangle.
Contest ends in
Sort by
recency
|
12 Discussions
|
Please Login in order to post a comment
I have tried sum of all natural number ie for 8th row no of elements is S(8) for 8 row and 5 col it is S(8) - S( 8 - 5)
similerly there is some pattern in no divisible by 7 since number for row 14 = S(14) - S( 14 - 14) - (S(14/7) * S(6))
I'm getting timed out!
Is anyone getting the same answer as I got? my output: 12 3842 2852 for input: 3 5 3 100 100 100 50; As per the best of my knowledge I have written correct logic for program. So can you tell me whether my second and third output number is wrong or right?why?
-
Got it for N == R. But not getting it right when R < N. Need to work on it. Any clue?
private static long pascal(int N, int R) { long count = 0; long div71 = 0; // divisible by 7 forming big pattern starting after row 49 long div72 = 0; // divisible by 7 forming small pattern starting after row 7 long div7 = 0; // Divisible by 7 long total = 0; int i = 0;
I almost solved it in O(1) time. But according to my algo for test case 100,100 no of entries divisible by 7 is 3217. But testcase answer is 5050-2361 = 2869. How I am able to find more no of entries divisible by 7, than actually is.
Here is my algo......
8th row (7C1, 7C2, ... 7C6) are all divisible by 7;
9th row (8C2, 8C3, ... 8C6) are all divisible by 7;
10th row (9C3, 9C4, ... 9C6) are all divisible by 7;
11th row (10C4, 10C5, 10C6) are all divisible by 7;
12th row (11C5, 11C6) are divisible by 7;
13th row (12C6) is only no. divisible by 7;
14th row NONE is divisible by 7;
So I generalise it like this....
8th row (1 to 6) total 6 entries
9th row (2 to 6) total 5 entries
.
.
13the row (6) total 1 entries
Sum of entries divisible by 7 till 14th row is 6+5+4+...+1 = 21;
Start again with 15th row count entries divisible by 7.
15th row (1-13) total 13 entries
16th row (2-13) total 12 entries
.
.
20th row (6-13) total 8 entries
21th row 0 entries
Sum it 13+12+...+8 = (7+6)+(7+5)+(7+4)+...+(7+1) = (42 + 21);
Find Sum again from row 22nd to 28
For rows(22-28): (42*2 + 21)
For rows(29-35): (42*3 + 21)
.
.
Actually we can generalise it........
For rows(1-7): (0);
For rows(8-14): (42*0 + 21);
For rows(15-21): (42*1 + 21);
For rows(22-28): (42*2 + 21);
For rows(29-35): (42*3 + 21);
For rows(36-42): (42*4 + 21);
.
.
.
For rows(92-98): (42*11 + 21);
For row 99th (98C1, 98C2, ... 98C97) total 97 entries are divisible by 7.
For row 100th 96 entries are divisible.
Total will be 3217 entries divisible by 7.
But in testcase answer it is 5050 - 2361 = 2689.
Can somebody explain where I am wrong....?
Please... Thanks...