📜  超级D号码

📅  最后修改于: 2021-05-04 10:41:37             🧑  作者: Mango

给定一个整数N ,任务是检查N是一个超级d号。

例子:

方法:这个想法是创建每个可能的字符串,将数字D,D串联很多次,然后检查串联是否以D * N D中的子字符串形式出现,其中D的范围为[2,9] 。
下面是上述方法的实现:

Java
// Java implementation to
// check if N is a super-d number
class GFG{
     
// Function to check if N
// is a super-d number
static boolean isSuperdNum(int n)
{
    for (int d = 2; d < 10; d++)
    {
        String subString = newString(d);
        if (String.valueOf(
           (d * Math.pow(n, d))).contains(subString))
            return true;
    }
    return false;
}
 
// Driver Code
private static String newString(int d)
{
    String ans = "";
    for (int i = 0; i < d; i++)
    {
        ans += String.valueOf(d);
    }
    return ans;
}
 
// Driver Code
public static void main(String[] args)
{
    int n = 261;
    if (isSuperdNum(n) == true)
        System.out.println("Yes");
    else
        System.out.println("No");
}
}
 
// This code is contributed by Rajput-Ji


Python3
# Python3 implementation to
# check if N is a super-d number
 
# Function to check if N
# is a super-d number
def isSuperdNum(n):
    for d in range (2, 10):
        substring = str(d) * d;
        if substring in str(d * pow(n, d)):
            return True
    return False
 
# Driver Code
n = 261
if isSuperdNum(n) == True:
    print("Yes")
else :
    print("No")


C#
// C# implementation to
// check if N is a super-d number
using System;
 
class GFG{
     
// Function to check if N
// is a super-d number
static bool isSuperdNum(int n)
{
    for(int d = 2; d < 10; d++)
    {
       String subString = newString(d);
       if (String.Join("",
          (d * Math.Pow(n, d))).Contains(subString))
           return true;
    }
    return false;
}
 
private static String newString(int d)
{
    String ans = "";
     
    for(int i = 0; i < d; i++)
    {
       ans += String.Join("", d);
    }
    return ans;
}
 
// Driver Code
public static void Main(String[] args)
{
    int n = 261;
     
    if (isSuperdNum(n) == true)
        Console.WriteLine("Yes");
    else
        Console.WriteLine("No");
}
}
 
// This code is contributed by Rajput-Ji


输出:
Yes

参考文献: OEIS