In this HackerEarth Supernatural problem solution, 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.
HackerEarth Supernatural problem solution.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int ans = 0;
cin >> n;
for(int i = 1; i <= 1000000; ++i){
int j = i;
int mul = 1;
bool f = 1;
while(j){
int val = j % 10;
if(val < 2){
f = 0;
break;
}else {
mul *= val;
}
j /= 10;
}
if(mul == n && f)++ans;
}
cout << ans << '\n';
return 0;
}
0 Comments