如果每个除数D除以,超级超级号码是以2为底的超级号码(pseudoprime) 。
一些超级数是:
341, 1387, 2047, 2701, 3277, 4033….
检查N是否为超级数
给定一个整数N ,任务是检查N是一个超级小数字。
例子:
Input: N = 341
Output: Yes
Input: N = 10
Output: No
方法:想法是生成数字N的所有除数,并为所有除数检查D除 。如果满足所有除数的条件,则该数字为超Poult数。
例如:
For N = 341,
Divisors of 341 are {1, 11, 31, 341} and,
Similarly, also gives integer value.
Therefore, 341 is a super-poulet number.
下面是上述方法的实现:
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