📜  无礼数字

📅  最后修改于: 2021-05-04 08:47:59             🧑  作者: Mango

如果Insolite Number可以被总和及其数字平方的乘积整除,则它是数字N。
很少的Insolite数字是:

检查一个数字是否是一个无礼数字

给定一个数字N ,任务是检查N是否是一个Insolite Number 。如果N是一个无礼数字,则打印“是”,否则打印“否”
例子:

方法:如果Insolite Number可被总和及其数字平方的乘积整除,则为N。因此,我们将找到N的数字平方和,N的数字平方乘积,然后检查N是否可被总和与乘积整除。如果可整,则打印“是”,否则打印“否”
下面是上述方法的实现:

C++
// C++ implementation for the
// above approach
 
#include 
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


输出:
Yes

时间复杂度: O(n)
参考:http://www.numbersaplenty.com/set/insolite_number/