/* Return the sum of the digits in the prime factorization of a composite number N.
   If N is a prime, the return value is 0 and isPrime is set to 1 */
long int getDigitSumFactorization(long int N, long int *isPrime)
{
    long int index = 0, sumFactor = 0, copyN = N;
    *isPrime = 0;

    if(N <= 1)
        return 0;

    for(index = 0; index < primeArrSize && primeArr[index] * primeArr[index] <= N; index++)
    {
        while(copyN % primeArr[index] == 0)
        {
            sumFactor += getDigitSum(primeArr[index]);
            copyN /= primeArr[index];
        }
    }

    if(copyN == N)
        /* N is a prime! */
        *isPrime = 1;
    else
        if(copyN > 1)
            sumFactor += getDigitSum(copyN);

    return sumFactor;
}
示例#2
0
bool check(int threshold, int rows, int cols, int row, int col, bool* visited)
{
    if(row >=0 && row < rows && col >= 0 && col < cols
        && getDigitSum(row) + getDigitSum(col) <= threshold
        && !visited[row* cols + col])
        return true;
    
    return false;
}
/* Return 1 if N is a Smith number. Return 0 otherwise */
int isSmithNumber(long int N)
{
    long int isPrime, digitSum, digitSumFactor;

    digitSumFactor = getDigitSumFactorization(N, &isPrime);
    if(isPrime)
        return 0;       /* A Smith number must be composite */

    digitSum = getDigitSum(N);
    return digitSum == digitSumFactor;
}