Thursday, August 28, 2014

CODE CHEF: October Challenge 2013 "Maxim and Dividers"

Hello Readers,

Today i am posting the solution of a "CODECHEF" problem. The problem was asked in the CODE CHEF: October Challenge 2013, known as  "Maxim and Dividers".
Here goes the Problem Statement.

Problem Statement

    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 477444 are lucky, 517467 — 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 Ttest 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

  • 1 ≤ T ≤ 10
  • 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




First Try it yourself...

Here is my solution in C for the above Problem:


#include<stdio.h>
#include<stdlib.h>
 
 int checkoverlucky(int i)
 {
   int k;
   
   while(i>0)
   {
   if(i%10==4||i%10==7)
   return 1;
   i=i/10;
   }
   return 0;
 }
  
int main()
{
int T,count=0,i;
int k=0;
long int n;


scanf("%d",&T);
if(T<1||T>10)
{
printf("Error in T");
exit(0);
}

while(k++<T)
{
i=4;
count=0;
   scanf("%ld",&n);
   if(n<1||n>1000000000)
   {
   printf("Error in n");
   exit(0);
   }
   while(i<=n)
   {
   if(n%i==0)
   if(checkoverlucky(i))
   {
   count++;
   }

            i++;
   }
   printf("%d \n",count);



}

return 0;
} 


Any suggestions are most welcome.. :) 

Viva La Raza
Sid 




No comments:

Post a Comment