Mehta's Dilemma
Practice
0 (0 votes)
Dynamic programming
Linear algebra
Hard
Approved
Mathematics
Open
Matrix exponentiation
Problem
13% Success 276 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Background:
Mehta's friend Verma has challenged him in a maths puzzle. The puzzle involves playing with digits, their product and square root.

Task:
Numbers which have product of their digits as perfect square in their decimal representation are called Fancy Numbers. So, you have to report the count of Fancy Numbers having length less than or equal to given number N. Length of the number is defined as number of digits in its decimal representation.

Input:
First Line of the input contains number of test cases T.
Next T Lines contain a single number N denoting the maximum length.

Output:
Output the count of Fancy Numbers having length less than or equal to given number N in a separate line for all test cases T modulo 109 + 7.

Note:
0 is a perfect square and has length 1.
Any number of length X does not have leading zeros i.e one is represented as 1 and not 01, 001.

Constraints:
Subtask 1:
1 <= T <= 10
1 <= N <= 10000
Subtask 2:
1 <= T <= 5
1 <= N <= 1018

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Linear AlgebraHardRecruitApprovedGrammar-VerifiedMathematicsMatrix Exponentiation
Points:50
4 votes
Tags:
Graph TheoryLinear AlgebraHardMatrix ExponentiationAlgorithmsRecursionMathematicsOpenApproved
Points:20
42 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsMathOpenSorting