📜  超级号码

📅  最后修改于: 2021-04-24 17:54:38             🧑  作者: Mango

如果每个除数D除以,超级超级号码是以2为底的超级号码(pseudoprime) 2^{D} - 2

一些超级数是:

检查N是否为超级数

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

例子:

方法:想法是生成数字N的所有除数,并为所有除数检查D除2^{D}-2   。如果满足所有除数的条件,则该数字为超Poult数。
例如:

下面是上述方法的实现:

Python3
# Python3 implementation to
# check if N is a super Poulet number
import math
 
# Function to find the divisors
def findDivisors(n):
    divisors = []
     
    # Loop to iterate over the
    # square root of the N
    for i in range(1,\
         int(math.sqrt(n) + 1)):
         
        if (n % i == 0) :
 
            # Check if divisors are equal
            if (n / i == i):
                divisors.append(i)
            else:
                divisors.append(i)
                divisors.append(int(n / i))
    return sorted(divisors)
     
# Function to check if N
# is a super Poulet number
def isSuperdNum(n):
    d = findDivisors(n)
     
    # Loop to check that every
    # divisor divides 2^D - 2
    for i in d:
        x = (2**i-2)/i
        if int(x) != x:
            return False
    return True
 
# Driver Code
if __name__ == "__main__":
    n = 341
    if isSuperdNum(n) == True:
        print("Yes")
    else :
        print("No")


C#
// C# implementation to
// check if N is a super Poulet number
using System;
using System.Collections.Generic;
 
class GFG
{
 
  // Function to find the divisors
  static List findDivisors(int n)
  {
    List divisors = new List();
 
    // Loop to iterate over the
    // square root of the N
    for (int i = 1; i < (Math.Sqrt(n) + 1); i++)
    {
      if (n % i == 0)
      {
 
        // Check if divisors are equal
        if (n / i == i)
          divisors.Add(i);
        else
        {
          divisors.Add(i);
          divisors.Add((n / i));
        }
      }
    }
    divisors.Sort();
    return divisors;
  }
 
  // Function to check if N
  // is a super Poulet number
  static bool isSuperdNum(int n)
  {
    List d = findDivisors(n);
 
    // Loop to check that every
    // divisor divides 2^D - 2
    foreach(int i in d)
    {
      double x = (Math.Pow(2, i) - 2) / i;
      if (Math.Truncate(x) != x)
        return false;
    }
    return true;
  }
 
  // Driver Code
  public static void Main(string[] args)
  {
    int n = 341;
    if (isSuperdNum(n) == true)
      Console.Write("Yes");
    else
      Console.Write("No");
  }
}
 
// This code is contributed by chitranayal.


输出:
Yes