GeeksforGeeks App
Open App
Browser
Continue

# Super-Poulet Number

Super-Poulet number is a Poulet number (pseudoprime) to base 2 if each and every divisor D divides .

Some of the super-poulet numbers are:

341, 1387, 2047, 2701, 3277, 4033….

### Check if N is a Super-poulet number

Given an integer N, the task is to check N is a Super-Poulet Number.

Examples:

Input: N = 341
Output: Yes
Input: N = 10
Output: No

Approach: The idea is to generate all the divisors of the number N and for all divisor check D divides . If this condition satisfy for all divisors then the number is super-poulet number.
For Example:

For N = 341,
Divisors of 341 are {1, 11, 31, 341} and,

Similarly, also gives integer value.
Therefore, 341 is a super-poulet number.

Below is the implementation of the above approach:

## C++

 // C++ implementation to// check if N is a super Poulet number#include  using namespace std; // Function to find the divisorsvector<int> findDivisors(int n){  vector<int> divisors;   // Loop to iterate over the  // square root of the N  for (int i = 1; i < (sqrt(n) + 1); i++) {    if (n % i == 0) {       // Check if divisors are equal      if (n / i == i)        divisors.push_back(i);      else {        divisors.push_back(i);        divisors.push_back((n / i));      }    }  }  sort(divisors.begin(), divisors.end());  return divisors;} // Function to check if N// is a super Poulet numberbool isSuperdNum(int n){  vector<int> d = findDivisors(n);   // Loop to check that every  // divisor divides 2^D - 2  for (int i : d) {    double x = (pow(2, i) - 2) / i;    if (floor(x) != x)      return false;  }  return true;} // Driver Codeint main(){  int n = 341;  if (isSuperdNum(n) == true)    cout << "Yes";  else    cout << "No";} // This code is contributed by phasing17.

## Java

 // Java implementation to// check if N is a super Poulet numberimport java.util.*; class GFG{   // Function to find the divisors  static ArrayList findDivisors(int n)  {     ArrayList divisors = new  ArrayList();     // 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));        }      }    }    Collections.sort(divisors);    return divisors;  }   // Function to check if N  // is a super Poulet number  static boolean isSuperdNum(int n)  {     ArrayList d = findDivisors(n);     // Loop to check that every    // divisor divides 2^D - 2    for(int i : d)    {      double x = (Math.pow(2, i) - 2) / i;      if (Math.floor(x) != x)        return false;    }    return true;  }   // Driver Code  public static void main(String[] args)  {    int n = 341;    if (isSuperdNum(n) == true)      System.out.print("Yes");    else      System.out.print("No");  }} // This code is contributed by phasing17.

## Python3

 # Python3 implementation to# check if N is a super Poulet numberimport math # Function to find the divisorsdef 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 numberdef 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 Codeif __name__ == "__main__":    n = 341    if isSuperdNum(n) == True:        print("Yes")    else :        print("No")

## C#

 // C# implementation to// check if N is a super Poulet numberusing System;using System.Collections.Generic; class GFG{   // Function to find the divisors  static List<int> findDivisors(int n)  {    List<int> divisors = new List<int>();     // 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<int> 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.

## Javascript

 

Output:

Yes

My Personal Notes arrow_drop_up