📜  信宝号

📅  最后修改于: 2021-04-23 15:45:51             🧑  作者: Mango

Belphegor数是回文数,因此该数的形式为

1(0...)666(0...)1

N个Belphegor编号由下式给出:

检查N是否是Belphegor号码

给定数字N ,任务是检查N是否是Belphegor数字。如果NBelphegor数字,则打印“是”,否则打印“否”

例子:

方法:想法是检查数字是否为回文,如果为回文,则检查数字应为1(0…)666(0…)1格式,如果数字为此格式,则打印“是”。 ” ,否则打印“否”

下面是上述方法的实现:

Python3
# Python3 implementation 
# of the above approach
         
# Function to check if the number 
# N is in the form 
# 1(0...)666(0...)1
def isinform(n):
    temp = str(n)
      
    Len = len(temp)
      
    # basic case
    if "666" not in temp or\
       Len<5 or Len % 2 == 0:
        return False
          
    mid = Len//2
    if not (temp[mid-1] == temp[mid]\
       and temp[mid-1] == '6' and\
                     temp[0] == '1'):
        return False
    for i in range(mid + 2, Len-1):
        if temp[i] != '0':
            return False
    return True
   
# Function to check if the number 
# N is palindrome
def ispalindrome(n):
    temp = str(n)
    if temp == temp[::-1]:
        return True
    return False
     
# Function to check if a number 
# N is Belphegor
def isBelphegor(n):       
    if ispalindrome(n):
        if isinform(n):
            return True
    return False 
        
        
# Driver Code  
n = 100666001;   
if isBelphegor(n):
    print("Yes")
else:
    print("No")


输出:
Yes