Supernatural

 Problem:-

You are given a number n.

A supernatural number is a number whose product of digits is equal to n, and in this number there is no digit 1.

Count the number of supernatural numbers for a given n.

Input

Contains a single integer n1 <= n <= 100.

Output

Print the number of supernatural numbers.

Sample Input
4
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are only two natural numbers, the product of the digits of which is 4 – 4, 22.

Logic:-

Here constrains for n is :-  n<=100   so multiplication of digits of a number should be less than 100;

and 1 should not in supernatural number (according to question) so the minimum number is 2.

and when we multiply 2

2=2

2*2=4

2*2*2=8

2*2*2*2=16

2*2*2*2*2=32

2*2*2*2*2*2=64

2*2*2*2*2*2*2=128  (which is greater then 100)

So the maximum length of the number is 6.

and we have to check from 2 to 1000000 (maximum number) for all the number . 

Code:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int count=0;
for(int i=2;i<=1000000;i++)
{
int j=i;
int mul=1;
int flag=0;
while(j)
{
int r=j%10;
// if r<2 i.e r is 1
// or 0 which is not
// allowed in supernatural
if(r<2)
{
flag=1;
break;
}
else
mul=mul*r;
j=j/10;
}
if(mul==n && flag==0)
count++;
}
cout<<count;
return 0;
}


Recommended post:-

Hackerearth Problems:-

Data structure:-

Key points:-

Leave a Reply

Your email address will not be published.