Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Super-D Numbers

  • Last Updated : 13 Jul, 2021

Given an integer N, the task is to check N is a super-d Number.
 

Super-D Number is a number N such that D*ND contains a substring made of D digits containing D only, where D is more than 1 and less than 10 
 

Examples: 
 

Input: N = 261 
Output: Yes 
Explanation: 
It will be true for D = 3 
D*ND = 3*2613 = 53338743 
which contains a substring made of 3 digits 333 containing 3 only.
Input: N = 10 
Output: No 
 

 

Approach: The idea is to create every possible string concatenating digit D, D number of times and then will check if the concatenation is present as a substring in D*ND or not, where D will be in the range [2, 9].
Below is the implementation of the above approach: 
 

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
Output: 
Yes

 

Time Complexity: O(1)

References: OEIS
 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!