Wednesday, November 20, 2024
Google search engine
HomeData Modelling & AISuper-Poulet Number

Super-Poulet Number

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

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 2^{D}-2        . 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, 
\frac{(2^{1} - 2)}{1} = 0
\frac{(2^{11} - 2)}{11} = \frac{2046}{11} = 186
\frac{(2^{31} - 2)}{31} = \frac{2147483646}{31} = 69273666
Similarly, \frac{(2^{341} - 2)}{341}        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 <bits/stdc++.h>
 
using namespace std;
 
// Function to find the divisors
vector<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 number
bool 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 Code
int 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 number
import java.util.*;
 
class GFG
{
 
  // Function to find the divisors
  static ArrayList<Integer> findDivisors(int n)
  {
     ArrayList<Integer> divisors = new  ArrayList<Integer>();
 
    // 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<Integer> 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 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<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




<script>
// Javascript implementation to
// check if N is a super Poulet number
 
// Function to find the divisors
function findDivisors(n){
    let divisors = []
     
    // Loop to iterate over the
    // square root of the N
    for(let i = 1; i < Math.floor(Math.sqrt(n) + 1); i++){
         
        if (n % i == 0) {
 
            // Check if divisors are equal
            if (n / i == i){
                divisors.push(i)
            }
            else{
                divisors.push(i)
                divisors.push(Math.floor(n / i))
            }
        }
    }
    return divisors.sort((a, b)=> a - b)
}
     
// Function to check if N
// is a super Poulet number
function isSuperdNum(n){
    let d = findDivisors(n)
     
    // Loop to check that every
    // divisor divides 2^D - 2
    for(let i in d){
        let x = (2**i - 2) / i
 
        if (Math.floor(x) != x){
            return false
        }
    }
    return true
}
// Driver Code
    let n = 341
    if(isSuperdNum(n) == true){
        document.write("Yes")
    }
    else {
        document.write("No")
    }
 
// This code is contributed by _saurabh_jaiswal
 
</script>


Output: 

Yes

 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Commit to GfG’s Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.

Last Updated :
27 Sep, 2022
Like Article
Save Article


Previous

<!–

8 Min Read | Java

–>


Next


<!–

8 Min Read | Java

–>

Share your thoughts in the comments

RELATED ARTICLES

Most Popular

Recent Comments