• + 0 comments
    #include <vector>
    #include <cmath>
    using namespace std;
    
    // Function to calculate the sum of digits of a number
    int sumOfDigits(int n) {
        int sum = 0;
        while (n > 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
    
    // Function to find the prime factors of a number
    vector<int> primeFactors(int n) {
        vector<int> factors;
        for (int i = 2; i <= sqrt(n); ++i) {
            while (n % i == 0) {
                factors.push_back(i);
                n /= i;
            }
        }
        if (n > 1) {
            factors.push_back(n);
        }
        return factors;
    }
    
    // Function to check if a number is a Smith number
    bool isSmithNumber(int n) {
        if (n < 2) return false; // Numbers less than 2 are not Smith numbers
    
        vector<int> factors = primeFactors(n);
    
        if (factors.size() == 1) {
            return false; // Prime numbers are not Smith numbers
        }
    
        int digitSum = sumOfDigits(n);
        int factorsDigitSum = 0;
    
        for (int factor : factors) {
            factorsDigitSum += sumOfDigits(factor);
        }
    
        return digitSum == factorsDigitSum;
    }
    
    int main() {
        int n;
        cin >> n;
    
        if (isSmithNumber(n)) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    
        return 0;
    }