समस्या विवरण
एक पूर्णांक दिया गया है, जांचें कि क्या यह संख्या अपने अंकों के फैक्टोरियल के योग से विभाज्य है।
उदाहरण: 19 → 1! + 9! = 1 + 362880 = 362881 → 362881 ÷ 19 = 19099 → विभाज्य
उदाहरण कोड
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 1 || n == 0) return 1;
return factorial(n - 1) * n;
}
bool isDigitsFactDivByNumber(int num) {
int temp = num;
int sum = 0;
while (num) {
int digit = num % 10;
sum += factorial(digit);
num /= 10;
}
return (sum % temp == 0);
}
int main() {
int number = 19;
if (isDigitsFactDivByNumber(number))
cout << "Yes, the number can divide the sum of factorial of digits.";
else
cout << "No, the number cannot divide the sum of factorial of digits.";
return 0;
}
आउटपुट
Yes, the number can divide the sum of factorial of digits.