## Interview Question

**Country:**United States

#include<stdio.h>

int main()

{

long long num,count=0;int i;

scanf("%lld",&num);

for(i=2;i*i<=num;i++)

{

if(num%i==0)

{

int factor2=num/i;

int k=i;

while(k)

{

int t=k%10;k/=10;

if(t==3||t==5||t==6){count++;break;}

}

if(k!=factor2)

{

while(factor2)

{

int t=factor2%10;factor2/=10;

if(t==3||t==5||t==6){count++;break;}

}

}

}

}

while(num)

{

int t=num%10;

num/=10;

if(t==3||t==5||t==6){count++;break;}

}

printf("%lld\n",count);

}

#include<stdio.h>

int main()

{

long long num,count=0;int i;

scanf("%lld",&num);

for(i=2;i*i<=num;i++)

{

if(num%i==0)

{

int factor2=num/i;

int k=i;

while(k)

{

int t=k%10;k/=10;

if(t==3||t==5||t==6){count++;break;}

}

if(k!=factor2)

{

while(factor2)

{

int t=factor2%10;factor2/=10;

if(t==3||t==5||t==6){count++;break;}

}

}

}

}

while(num)

{

int t=num%10;

num/=10;

if(t==3||t==5||t==6){count++;break;}

}

printf("%lld\n",count);

}

There is no middle of anything when we are looking at a number. A number, rather more precisely integer is given by this regex (ignoring sign) :

That would mean, in a context free way, it can be written as :

That is how you should define middle. In this definition, of course middle becomes meaningless. Example: 34543 . What is the middle? My grammar of course is terribly ambiguous, but hope I did make the point.

Now, of course there are two problems.

1. Get all the factors of a number. This is not very interesting problem.

[ geeksforgeeks.org/find-divisors-natural-number-set-1/ ]

2. A predicate to declare if a number is a special number. That is slightly more interesting.

But then fairly trivially done by (with proper collection minus and subset definition ):

But the bigger question is, why write this way? It is terribly un-optimal !Clearly there are better way to do so? As it turned out, there is!!

Now this is cleaner, neater, and optimal. Now it is trivial to generate the appropriate imperative code.

- NoOne March 07, 2018