Friday 1 November 2013

Maxim and Dividers - Solution



Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.

If you remember, lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky, 5, 17, 467 — aren't.

Now Maxim is interested in the next information: what is the number of the integer positive dividers of number n, which are overlucky.

We call number overlucky if it is possible to remove some, but not all, digits and during bonding the remaining digits we will receive a lucky number. For example, number 72344 — overlucky, because it is possible to remove digits 2 and 3, and get number 744, which is lucky. Number 223 isn't overlucky.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Single line of each test case contains an integer n.

Output

For each test case on different lines print the answer to the problem.

Constraints

  • 1T10
  • 1 ≤ n ≤ 10^9

Example

Input:
10
1
2
3
4
5
6
7
8
9
10
 
Output:
0
0
0
1
0
0
1
1
0
0
 

Solution:

#include<stdio.h>
 
int isOverLucky(int);
int fun(int);
int main()
{
        int i,t,num,j;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {
               scanf("%d",&num);
               printf("%d\n",fun(num));
        }
        return 0;
}
 
int isOverLucky(int n)
{
        while(n)
        {
               if(n%10==4 || n%10==7)
                       return 1;
               n/=10;
        }
 
        return 0;
}
 
int fun(int n)
{
        int i,counter=0;
        for(i=1;i*i<n;i++)
               if(n%i==0)
                       counter+=isOverLucky(i)+isOverLucky(n/i);
        if(n%i==0)
               counter+=isOverLucky(i);
        return counter;
}

No comments:

Post a Comment