📜  眼角膜数字

📅  最后修改于: 2021-04-22 07:58:21             🧑  作者: Mango

当且仅当当a> b> c> 0时,爱多纳尔数N时,它才是数字N。
几个理想的数字是:

检查数字是否为Idoneal数字

给定一个数字N ,任务是检查N是否是一个爱奥尼亚尔编号。如果N是一个编号,则打印“是”,否则打印“否”
例子:

方法的想法是运行三个从“ 1”到“ N”的嵌套循环,并检查ab + bc + ca是否等于“ N”。如果ab + bc + ca等于’N’,则返回false,否则在循环结束时返回true。
下面是上述方法的实现:

C++
// C++ implementation for the
// above approach
 
#include 
using namespace std;
 
// Function to check if number
// is an Idoneal numbers
bool isIdoneal(int n)
{
    // iterate for all
    // triples pairs (a, b, c)
    for (int a = 1; a <= n; a++) {
        for (int b = a + 1; b <= n; b++) {
            for (int c = b + 1; c <= n; c++) {
 
                // if the condition
                // is satisfied
                if (a * b + b * c + c * a == n)
                    return false;
            }
        }
    }
    return true;
}
 
// Driver Code
int main()
{
    int N = 10;
 
    // Function Call
    if (isIdoneal(N))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Java
// Java implementation for the
// above approach
import java.lang.*;
 
class GFG{
     
// Function to check if number
// is an Idoneal numbers
static boolean isIdoneal(int n)
{
     
    // Iterate for all
    // triples pairs (a, b, c)
    for(int a = 1; a <= n; a++)
    {
       for(int b = a + 1; b <= n; b++)
       {
          for(int c = b + 1; c <= n; c++)
          {
               
             // If the condition
             // is satisfied
             if (a * b + b * c + c * a == n)
                 return false;
          }
       }
    }
    return true;
}
 
// Driver Code
public static void main(String[] args)
{
    int N = 10;
 
    // Function Call
    if (isIdoneal(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 number
# is an Idoneal numbers
def isIdoneal(n):
 
    # Iterate for all
    # triples pairs (a, b, c)
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            for c in range(b + 1, n + 1):
 
                # If the condition
                # is satisfied
                if (a * b + b * c + c * a == n):
                    return False
 
    return True
 
# Driver Code
N = 10
 
# Function call
if (isIdoneal(N)):
    print("Yes")
else:
    print("No")
 
# This code is contributed by Vishal Maurya.


C#
// C# implementation for the
// above approach
using System;
class GFG{
     
// Function to check if number
// is an Idoneal numbers
static bool isIdoneal(int n)
{
     
    // Iterate for all
    // triples pairs (a, b, c)
    for(int a = 1; a <= n; a++)
    {
        for(int b = a + 1; b <= n; b++)
        {
            for(int c = b + 1; c <= n; c++)
            {
                 
                // If the condition
                // is satisfied
                if (a * b + b * c + c * a == n)
                    return false;
            }
        }
    }
    return true;
}
 
// Driver Code
public static void Main()
{
    int N = 10;
 
    // Function Call
    if (isIdoneal(N))
        Console.Write("Yes");
    else
        Console.Write("No");
}
}
 
// This code is contributed by Code_Mech


Javascript


输出:
Yes

时间复杂度: O(n * n * n)
参考:https://en.wikipedia.org/wiki/Idoneal_number