Rahul and Lucky numbers

3.5

6 votes
Very-Easy
Problem

Rahul considers the numbers 3 and 5 to be lucky. All numbers containing only 3 and 5 are also considered lucky. Given a lucky number N, find the index of this number among all sorted lucky numbers. For this problem indexing starts from 1 instead of 0. So the first lucky number is 3, second lucky number is 5 and so on.

INPUT: The first line will contain an integer T denoting the number of test-cases. Each test case will contain a positive integer N as described in the problem statement.

OUTPUT: T lines containing the answer for each test case.

CONSTRAINTS: 1 <= T <= 1000 1 <= N <= 10000000000

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

If you consider the sorted list of all lucky numbers, 333 lies on the 7th position, therefore the answer is 7.

Editor Image

?