As you read in the problem statement, you have to find out whether a number has a divisor which is also a lucky number, so iterate from 1 to n, if n is divisible by i, then check whether it is a lucky number or not?
Easily write a function that take a number and tell whether it is lucky or not, in other words the function checks whether all of the digits in the given number are 4 or 7.
- bool isLucky(int n)
- {
- int rem;
- while(n)
- {
- rem = n%10;
- if(rem != 7 && rem != 4)
- return false;
- n /= 10;
- }
- return true;
- }
Wrong answer it want to check if it is divisible by lucky number or not in other words 799 is lucky number because it can be divided with 47
ReplyDeleteWrong answer it want to check if it is divisible by lucky number or not in other words 799 is lucky number because it can be divided with 47
ReplyDelete