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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #148: Exploring Pascal's triangle.

Project Euler #148: Exploring Pascal's triangle.

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 148 from projecteuler.net

We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by 7:

However, if we check the first one hundred rows, we will find that only 2361 of the 5050 entries are not divisible by 7.

Find the number of entries which are not divisible by 7 in the first rows and first columns of Pascal's triangle. Here, "column" means a column when the triangle is written this way:

Since the answer can be very large, output it modulo .

Input Format

The first line of input contains , the number of test cases.

Each test case consists of one line containing two integers, and , separated by a space.

Constraints


Test files #01-#03:
Test files #04-#06:
Test files #07-#09:
Test files #10-#12:
Test files #13-#15: No additional constraints.

Output Format

For each test case, output a single line containing a single integer, the answer for that test case.

Sample Input

3
5 3
100 100
100 50

Sample Output

12
2361
1622

Explanation

In the first test case, the following are the entries in the first rows and first columns: (highlighted in bold)

There are entries all in all, and they are all not divisible by . Thus, the answer is .

The second test case is mentioned in the problem statement.

Author

kevinsogo

Difficulty

Hard

Max Score

100

Submitted By

264

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature