Open In App

Insolite Numbers

Last Updated : 23 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Insolite Number is a number N if it is divisible by the Sum and by the Product of the squares of its digits.
Few Insolite numbers are: 
 

111, 11112, 1122112, 111111111, 122121216, 1111112112… 
 

 

Check if a number is an Insolite Number

Given a number N, the task is to check if N is an Insolite Number or not. If N is an Insolite Number then print “Yes” else print “No”.
Examples: 
 

Input: N = 1122112 
Output: Yes 
Explanation: 
1122112 is an Insolite Number because 
sum of the squares of its digits 1^2 + 1^2 + 2^2 + 2^2 + 1^2 + 1^2 + 2^2 = 16 
the product of the squares of its digits (1*1*2*2*1*1*2)^2 = 64 
And 1122112 is divisible by both 16 and 64.
Input: N = 11 
Output: No 
Explanation: 

 
 

 

 

Approach: Insolite Number is a number N if it is divisible by the sum and by the product of the squares of its digits. So we will find the sum of squares of digits of N, product of squares of digits of N and then check if N is divisible by both the sum and product or not. If divisible then print “Yes” else print “No”.
Below is the implementation of the above approach:
 

 

C++




// C++ implementation for the
// above approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to check if a number
// is an Insolite numbers
bool isInsolite(int n)
{
    int N = n;
 
    // To store sum of squares of digits
    int sum = 0;
 
    // To store product of
    // squares of digits
    int product = 1;
 
    while (n != 0) {
        // extracting digit
        int r = n % 10;
        sum = sum + r * r;
        product = product * r * r;
        n = n / 10;
    }
 
    return (N % sum == 0)
           && (N % product == 0);
}
 
// Driver Code
int main()
{
    int N = 111;
 
    // Function Call
    if (isInsolite(N))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Java




// Java implementation for the
// above approach
class GFG{
     
// Function to check if a number
// is an Insolite numbers
static boolean isInsolite(int n)
{
    int N = n;
 
    // To store sum of squares of digits
    int sum = 0;
 
    // To store product of
    // squares of digits
    int product = 1;
 
    while (n != 0)
    {
         
        // extracting digit
        int r = n % 10;
        sum = sum + r * r;
        product = product * r * r;
        n = n / 10;
    }
 
    return (N % sum == 0) &&
           (N % product == 0);
}
 
// Driver Code
public static void main (String[] args)
{
    int N = 111;
 
    // Function Call
    if (isInsolite(N))
        System.out.print("Yes");
    else
        System.out.print("No");
}
}
 
// This code is contributed by rock_cool


Python3




# Python3 implementation for the
# above approach
 
# Function to check if a number
# is an Insolite numbers
def isInsolite(n):
    N = n;
 
    # To store sum of squares of digits
    sum = 0;
 
    # To store product of
    # squares of digits
    product = 1;
 
    while (n != 0):
         
        # extracting digit
        r = n % 10;
        sum = sum + r * r;
        product = product * r * r;
        n = n // 10;
 
    return ((N % sum == 0) and
            (N % product == 0));
 
# Driver Code
if __name__ == '__main__':
    N = 111;
 
    # Function Call
    if (isInsolite(N)):
        print("Yes");
    else:
        print("No");
 
# This code is contributed by 29AjayKumar


C#




// C# implementation for the
// above approach
using System;
class GFG{
     
// Function to check if a number
// is an Insolite numbers
static bool isInsolite(int n)
{
    int N = n;
 
    // To store sum of squares of digits
    int sum = 0;
 
    // To store product of
    // squares of digits
    int product = 1;
 
    while (n != 0)
    {
         
        // extracting digit
        int r = n % 10;
        sum = sum + r * r;
        product = product * r * r;
        n = n / 10;
    }
 
    return (N % sum == 0) &&
           (N % product == 0);
}
 
// Driver Code
public static void Main()
{
    int N = 111;
 
    // Function Call
    if (isInsolite(N))
        Console.Write("Yes");
    else
        Console.Write("No");
}
}
 
// This code is contributed by Code_Mech


Javascript




<script>
 
// Javascript implementation for the
// above approach
 
 
    // Function to check if a number
    // is an Insolite numbers
    function isInsolite( n) {
        let N = n;
 
        // To store sum of squares of digits
        let sum = 0;
 
        // To store product of
        // squares of digits
        let product = 1;
 
        while (n != 0) {
 
            // extracting digit
            let r = n % 10;
            sum = sum + r * r;
            product = product * r * r;
            n = parseInt(n / 10);
        }
 
        return (N % sum == 0) && (N % product == 0);
    }
 
    // Driver Code
      
        let N = 111;
 
        // Function Call
        if (isInsolite(N))
            document.write("Yes");
        else
            document.write("No");
 
// This code contributed by Rajput-Ji
 
</script>


Output: 

Yes

 

Time Complexity: O(n) 
Reference: http://www.numbersaplenty.com/set/insolite_number/
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads