Insolite Numbers
Last Updated :
23 Mar, 2021
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++
#include <bits/stdc++.h>
using namespace std;
bool isInsolite( int n)
{
int N = n;
int sum = 0;
int product = 1;
while (n != 0) {
int r = n % 10;
sum = sum + r * r;
product = product * r * r;
n = n / 10;
}
return (N % sum == 0)
&& (N % product == 0);
}
int main()
{
int N = 111;
if (isInsolite(N))
cout << "Yes" ;
else
cout << "No" ;
return 0;
}
|
Java
class GFG{
static boolean isInsolite( int n)
{
int N = n;
int sum = 0 ;
int product = 1 ;
while (n != 0 )
{
int r = n % 10 ;
sum = sum + r * r;
product = product * r * r;
n = n / 10 ;
}
return (N % sum == 0 ) &&
(N % product == 0 );
}
public static void main (String[] args)
{
int N = 111 ;
if (isInsolite(N))
System.out.print( "Yes" );
else
System.out.print( "No" );
}
}
|
Python3
def isInsolite(n):
N = n;
sum = 0 ;
product = 1 ;
while (n ! = 0 ):
r = n % 10 ;
sum = sum + r * r;
product = product * r * r;
n = n / / 10 ;
return ((N % sum = = 0 ) and
(N % product = = 0 ));
if __name__ = = '__main__' :
N = 111 ;
if (isInsolite(N)):
print ( "Yes" );
else :
print ( "No" );
|
C#
using System;
class GFG{
static bool isInsolite( int n)
{
int N = n;
int sum = 0;
int product = 1;
while (n != 0)
{
int r = n % 10;
sum = sum + r * r;
product = product * r * r;
n = n / 10;
}
return (N % sum == 0) &&
(N % product == 0);
}
public static void Main()
{
int N = 111;
if (isInsolite(N))
Console.Write( "Yes" );
else
Console.Write( "No" );
}
}
|
Javascript
<script>
function isInsolite( n) {
let N = n;
let sum = 0;
let product = 1;
while (n != 0) {
let r = n % 10;
sum = sum + r * r;
product = product * r * r;
n = parseInt(n / 10);
}
return (N % sum == 0) && (N % product == 0);
}
let N = 111;
if (isInsolite(N))
document.write( "Yes" );
else
document.write( "No" );
</script>
|
Time Complexity: O(n)
Reference: http://www.numbersaplenty.com/set/insolite_number/
Share your thoughts in the comments
Please Login to comment...