Sort by

recency

|

133 Discussions

|

  • + 0 comments
    public static int solve(int nn) {
        // Write your code here
                      int ds=0;
            int temp=nn;
            int n=nn;
            List<Integer> a=new ArrayList<>();
            while(temp>0){
                ds+=temp%10;
                temp/=10;
            }
            
             while (n % 2 == 0) {
               a.add(2);
                n /= 2;
            }
            for (int i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    a.add(i);
                    n /= i;
                }
            }
     
            if (n > 2)
               a.add(n);
            
            
            int fsum=0;
            
            for(int i:a)
            {
                while(i>0){
                    fsum+=i%10;
                    i=i/10;
                }
            }
            //System.out.println(a);
            if(fsum==ds)
                return 1;
            return 0;
        }
    
  • + 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;
    }
    
  • + 0 comments

    import math

    def check_condition(n): # Function to compute the sum of digits of a number def sum_of_digits(num): return sum(int(digit) for digit in str(num))

    # Compute the sum of digits of (n-1)
    sum_digits_n_minus_1 = sum_of_digits(n - 1)
    
    # Initialize sum of prime factors
    prime_factors_sum = 0
    
    # Check for factors of 2
    while n % 2 == 0:
        prime_factors_sum += 2
        n //= 2
    
    # Check for odd factors from 3 upwards
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            prime_factors_sum += i
            n //= i
    
    # If n is still greater than 2, it's prime and should be added
    if n > 2:
        prime_factors_sum += n
    
    # Calculate the sum of digits of the sum of prime factors
    sum_digits_prime_factors_sum = sum_of_digits(prime_factors_sum)
    
    # Compare the two sums modulo 9 + 1
    if sum_digits_n_minus_1 == sum_digits_prime_factors_sum:
    
        Variable Naming: Renamed variables for clarity ( [sum](https://r2park.net/) _of_digits_of_numbers to sum_digits_n_minus_1, etc.).
        return 1
    else:
        return 0
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int a=sc.nextInt();
            int s=0;
            int b=a;
            for(int x=2;x<=a;x++)
            {
                while(a%x==0)
                {
                    a=a/x;
                    int q=x;
                    while(q>0)
                    {
                        s=s+q%10;
                        q=q/10;
                    }
                }
            }        
            int u=0;
            while(b>0)
            {
                u=u+b%10;
                b=b/10;
            }
            
            if(u==s)
            {
                System.out.println("1");
            }
            else
            {
                System.out.println("0");
            }
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        }
    }
    
  • + 0 comments
    def primeFactors(n):
         
        # Print the number of two's that divide n
        a = []
        while n % 2 == 0:
            a.append(2)
            n = n // 2
             
        # n must be odd at this point
        # so a skip of 2 ( i = i + 2) can be used
        for i in range(3,int(math.sqrt(n))+1,2):
             
            # while i divides n , print i and divide n
            while n % i== 0:
                a.append(i)
                n = n // i
                 
        # Condition if n is a prime
        # number greater than 2
        
        if n > 2:
            a.append(n)
        return a
    def sum_of_digits(n):
        s=0
        while(n!=0):
            s+=n%10
            n=n//10
        return s
    
    def solve(n):
        # Write your code here
        a=primeFactors(n)
        s = 0
        for i in range(len(a)):
            if a[i] <10:
                s+=a[i]
            else:
                s+=sum_of_digits(a[i])
        s1 = sum_of_digits(n)
        if s1 == s:
            return 1
        else:
            return 0