📜  检查号码是否为阿联酋

📅  最后修改于: 2021-04-23 20:24:09             🧑  作者: Mango

给定数字“ n”,检查它是否为酋长国。
一个酋长词(当拼写倒写时为“ semiprime”)是根据其拼写方式得出其定义的。因此,emirpimes本身就是一个半素数(两个质数的乘积),而其数字的颠倒又给出了另一个新数字,它也是一个半质数。因此,根据定义,我们可以得出以下结论:回文数不能算作成文,因为数字的颠倒不会给出任何新数字,而是会再次形成相同的数字。

例子 :

方法 :

  1. 首先检查输入的数字本身是否为半素数。
  2. 如果是,则通过反转数字来形成一个数字。
  3. 现在,将此数字与最初输入的数字进行比较,以确定该数字是否为回文。
  4. 如果该数字不是回文,请检查此新数字是否也是半素数。
  5. 如果是,则最初输入的号码被报告为酋长国。
C++
// CPP code to check whether
// a number is Emirpimes or not
#include 
using namespace std;
  
// Checking whether a number
// is semi-prime or not
int checkSemiprime(int num)
{
    int cnt = 0;
    for (int i = 2; cnt < 2 &&
                    i * i <= num; ++i)
    {
        while (num % i == 0)
        {
            num /= i;
  
            // Increment count of
            // prime numbers
            ++cnt;
        }
    }
  
    // If number is still greater than 1, after
    // exiting the for loop add it to the count
    // variable as it indicates the number is
    // a prime number
    if (num > 1)
        ++cnt;
  
    // Return '1' if count is 
    // equal to '2' else return '0'
    return cnt == 2;
}
  
// Checking whether a number
// is emirpimes or not
bool isEmirpimes(int n)
{
    // Number itself is not semiprime.
    if (checkSemiprime(n) == false)
        return false;
  
    // Finding reverse of n.
    int r = 0;
    for (int t=n; t!=0; t=t/n)
        r = r * 10 + t % 10;
  
    // The definition of emirpimes excludes
    // palindromes, hence we do not check
    // further, if the number entered is a
    // palindrome
    if (r == n)
        return false;
  
    // Checking whether the reverse of the
    // semi prime number entered is also
    // a semi prime number or not
    return (checkSemiprime(r));
}
  
// Driver Code
int main()
{
    int n = 15;
    if (isEmirpimes(n))
    cout << "Yes";
    else
        cout << "No";
    return 0;
}


Java
// Java code to check whether a
// number is Emirpimes or not
import java.io.*;
  
class GFG 
{
      
    // Checking whether a number
    // is semi-prime or not
    static boolean checkSemiprime(int num)
    {
        int cnt = 0;
        for (int i = 2; cnt < 2 && 
                        i * i <= num; ++i)
        {
            while (num % i == 0)
            {
                num /= i;
      
                // Increment count of
                // prime numbers
                ++cnt;
            }
        }
      
        // If number is still greater than 1,
        // after exiting the for loop add it 
        // to the count variable as it indicates
        // the number is a prime number
        if (num > 1)
            ++cnt;
      
        // Return '1' if count is equal
        // to '2' else return '0'
        return cnt == 2;
    }
      
    // Checking whether a number
    // is emirpimes or not
    static boolean isEmirpimes(int n)
    {
        // Number itself is not semiprime.
        if (checkSemiprime(n) == false)
            return false;
      
        // Finding reverse of n.
        int r = 0;
        for (int t = n; t != 0; t = t / n)
            r = r * 10 + t % 10;
      
        // The definition of emirpimes excludes
        // palindromes, hence we do not check
        // further, if the number entered is a
        // palindrome
        if (r == n)
            return false;
      
        // Checking whether the reverse of the
        // semi prime number entered is also
        // a semi prime number or not
        return (checkSemiprime(r));
    }
  
    // Driver Code
    public static void main (String[] args)
    {
        int n = 15;
        if (isEmirpimes(n))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}
  
// This code is contributed by Ajit.


Python3
# Python3 code to check whether 
# a number is Emirpimesor not 
  
# Checking whether a number 
# is semi-prime or not 
def checkSemiprime(num): 
  
    cnt = 0;
    i = 2;
    while (cnt < 2 and (i * i) <= num): 
      
        while (num % i == 0):
            num /= i; 
  
            # Increment count of 
            # prime numbers 
            cnt += 1;
        i += 1;
  
    # If number is still greater than 1, 
    # after exiting the add it to the 
    # count variable as it indicates 
    # the number is a prime number 
    if (num > 1): 
        cnt += 1; 
  
    # Return '1' if count is equal 
    # to '2' else return '0' 
    return cnt == 2; 
  
# Checking whether a number 
# is emirpimes or not 
def isEmirpimes(n): 
      
    # Number itself is not semiprime. 
    if (checkSemiprime(n) == False): 
        return False; 
  
    # Finding reverse of n. 
    r = 0;
    t = n;
    while (t != 0): 
        r = r * 10 + t % 10;
        t = t / n;
  
    # The definition of emirpimes excludes 
    # palindromes, hence we do not check 
    # further, if the number entered 
    # is a palindrome 
    if (r == n): 
        return false; 
  
    # Checking whether the reverse of the 
    # semi prime number entered is also 
    # a semi prime number or not 
    return (checkSemiprime(r)); 
  
# Driver Code 
n = 15; 
if (isEmirpimes(n)): 
    print("No"); 
else:
    print("Yes"); 
  
# This code is contributed by mits


C#
// C# code to check whether a
// number is Emirpimes or not
using System;
  
class GFG
{
      
    // Checking whether a number
    // is semi-prime or not
    static bool checkSemiprime(int num)
    {
        int cnt = 0;
        for (int i = 2; cnt < 2 && 
                        i * i <= num; ++i)
        {
            while (num % i == 0)
            {
                num /= i;
      
                // Increment count of
                // prime numbers
                ++cnt;
            }
        }
      
        // If number is still greater than 1, 
        // after exiting the for loop add it 
        // to the count variable as it 
        // indicates the number is a prime number
        if (num > 1)
            ++cnt;
      
        // Return '1' if count is equal
        // to '2' else return '0'
        return cnt == 2;
    }
      
    // Checking whether a number
    // is emirpimes or not
    static bool isEmirpimes(int n)
    {
        // Number itself is not semiprime.
        if (checkSemiprime(n) == false)
            return false;
      
        // Finding reverse of n.
        int r = 0;
        for (int t = n; t != 0; t = t / n)
            r = r * 10 + t % 10;
      
        // The definition of emirpimes excludes
        // palindromes, hence we do not check
        // further, if the number entered is a
        // palindrome
        if (r == n)
            return false;
      
        // Checking whether the reverse of the
        // semi prime number entered is also
        // a semi prime number or not
        return (checkSemiprime(r));
    }
  
    // Driver Code
    public static void Main ()
    {
        int n = 15;
        if (isEmirpimes(n))
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}
  
// This code is contributed by anuj_67.


PHP
 1)
        ++$cnt;
  
    // Return '1' if count
    // is equal to '2' else
    // return '0'
    return $cnt == 2;
}
  
// Checking whether a number
// is emirpimes or not
function isEmirpimes($n)
{
      
    // Number itself is
    // not semiprime.
    if (checkSemiprime($n) == false)
        return false;
  
    // Finding reverse
    // of n.
    $r = 0;
    for ($t = $n; $t != 0; $t = $t / $n)
         $r = $r * 10 + $t % 10;
  
    // The definition of emirpimes  
    // excludes palindromes,hence  
    // we do not check further, 
    // if the number entered 
    // is a palindrome
    if ($r == $n)
        return false;
  
    // Checking whether the 
    // reverse of the
    // semi prime number 
    // entered is also
    // a semi prime number 
    // or not
    return (checkSemiprime($r));
}
  
    // Driver Code
    $n = 15;
    if (isEmirpimes($n))
      
    echo "No";
    else
    echo "Yes";
  
// This code is contributed by Ajit.
?>


输出 :

Yes