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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #111: Primes with runs

Project Euler #111: Primes with runs

Problem
Submissions
Leaderboard
Discussions

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

Considering -digit primes containing repeated digits it is clear that they cannot all be the same: is divisible by , is divisible by , and so on. But there are nine -digit primes containing three ones: .

We shall say that represents the maximum number of repeated digits for an -digit prime where is the repeated digit; represents the number of such primes; and represents the set of these primes.

So is the maximum number of repeated digits for a -digit prime where one is the repeated digit, there are such primes, and . It turns out that for , it is only possible to have repeated digits, but there are such cases.

Determine the set for a given values of and .

Input Format

First line contains an integer denoting the number of test cases.
Each of the following lines contain two integers and .

Constraints


Output Format

For each of test cases print one line containing all primes that belong to in ascending order.

Sample Input

2
4 1
4 0

Sample Output

1117 1151 1171 1181 1511 1811 2111 4111 8111
1009 2003 3001 4001 4003 4007 5003 5009 6007 7001 8009 9001 9007

Author

Alex_2oo8

Difficulty

Easy

Max Score

100

Submitted By

606

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