Blum Integer


The problem statement includes checking the given numbers which will be the user input, if it is a Blum number or not.

A Blum integer is a semiprime number whose distinct prime factors a and b are of the form 4t+3, where t is some positive integer. A semiprime number is a number which is a product of exactly two prime numbers or a natural number which has exactly two factors which are prime numbers. In case of semiprime numbers, the factors may be equal.

In case any number N which is a blum integer, it must have only two factors such that N=a*b other than 1 and the number itself and the two factors, a and b must be distinct prime numbers which are of the form 4t+3(for any positive integer t).

The first few blum integers are 21, 33, 57, 69, 77, 93, 129, 133, 141……

Any even natural number can’t be a blum integer as the product of two distinct prime factors which are of form 4t+3 (i.e. an odd number) will always be an odd number greater than 20.

In this problem, we will be given a number N and we need to check if the number is a blum integer or not.

Example

INPUT : N=57
OUTPUT : yes

Explanation : The number given in the input is 57. The number 57 can be expressed as the product of 19 and 3 (i.e. 19*3). Since both the factors are distinct prime numbers and are of the form 4t+3.

19=4*4+3, the value of t is 4 in this case.

3=4*0+3, the value of t is 0.

Hence, the number 57 is a blum integer.

INPUT : N=49
OUTPUT : No

Explanation : The number given is 49 which can be expressed as 7*7. Since, 7 is a prime number but for a number to be a blum integer it should be the product of two distinct prime numbers. Hence, 49 is not a blum integer.

INPUT : N=35
OUTPUT : No

Explanation : The number 35 can be expressed as product of 7 and 5 (i.e. 7*5). Both the numbers are distinct prime numbers and 7 is of the form 4t+3 but 5 can’t be expressed as 4t+3 for any integer value of t. Hence, 35 is not a blum integer.

Let’s understand the algorithm in order to check if the number is a blum integer or not.

Algorithm

To check if the number is a blum integer or not, we can simply find all the prime numbers until that number and then check if the product of two distinct prime numbers of the form 4t+3 can make up the given number.

We will use the concept of the sieve of eratosthenes to find all the prime numbers until the given number N. The sieve of eratosthenes is the most efficient method to find the prime number up to any given number.

  • In this method, we will make a boolean array of size N+1, where N will be the given number. We will store true if the number is a prime number at the index value equal to the number else we will store false in the array.

  • To update false at index value corresponding to non-prime numbers until N, we will iterate in a for loop from i=2 to i<=sqrt(N) because any number less than or equal to N, if it is not a prime number there must be a factor which lies in the range [2, sqrt(N)].

  • If the arr[i] is true corresponding to the value of i, we will iterate in a nested loop from p=i*i until p<=N and update false at all the next multiples of p. And if it is false at the corresponding value of i, we will iterate for the next value of i.

Using a sieve of eratosthenes, we can get all the prime numbers from 1 to N. Now, iterating in a for loop in the array we will check if there exists any prime number which is the factor of the given number N and is of the form 4t+3 and the quotient of the prime number which divides N is also a distinct prime number of the form 4t+3. If all the above conditions are satisfied, the given number N will be a blum integer else it is not.

We will use this algorithm in our approach in order to solve the problem efficiently.

Approach

The steps to implement the algorithm in our approach to check if N is a blum integer or not are given below −

  • We will make a function to check if the number is a blum integer or not.

  • In the function, using the concept of sieve of eratosthenes we will store true in a boolean array of size N+1 for all the prime numbers till N at the corresponding index.

  • Iterating in a for loop from i=2 to i<=N to check if any prime number of the form 4t+3 is a factor of the given number.

  • If we find any prime number which is the factor of N and is of the form 4t+3, we will store the quotient of N divided by that prime number.

  • If the quotient is also a prime number and of the form 4t+3, we will return true else we will return false.

  • If the function returns true then the number is a blum integer.

Example

The C++ code for the approach −

// C++ program to check if the number is a blum integer or not
#include <bits/stdc++.h>

using namespace std;

// to check if N is a blum integer or not
bool check(int N){
   bool a[N + 1]; //to store true corresponding to the index value equal to prime number
    memset(a,true,sizeof(a));

   // to update the array with false at index value corresponding to non prime numbers
   for (int i = 2; i<=sqrt(N); i++) {

      //if i is a prime number
      if (a[i] == true) {

         //updating false at all the multiples of i less than or equal to N from i*i
         for (int p = i * i; p <= N; p += i)
            a[p] = false;
      }
   }

   //to check if there exist distinct prime numbers whose product is equal to N
   for (int i = 2; i <= N; i++) {
      if (a[i]) {

          //if i is the prime factor of the form 4t+3
         if ((N % i == 0) && ((i - 3) % 4) == 0) {
            int quotient = N / i;
            //to check if quotient*i=N and both are distinct prime numbers of form 4t+3
            if(quotient!=i && a[quotient] && (quotient-3)%4==0){
                return true;
            } else {
               return false;
            }
         }
      }
   }
   return false;
}
int main(){
   
   int N;
   N=469;
   //calling the function
   if (check(N)==true) //if function returns true, it is a blum integer
      cout <<N<<" is a blum integer."<<endl;
   else
      cout <<N<<" is not a blum integer."<<endl;
   return 0;
}

Output

469 is a blum integer.

Time Complexity : O(N*log(log(N), as it is the time complexity of sieve of eratosthenes.

Space Complexity : O(N), because we used an array of size N+1 to store prime numbers.

Conclusion

The concept of blum integers was discussed in the article. We came up with an efficient approach to check if the number is a blum integer or not using the concept of sieve of eratosthenes in C++ in this article.

I hope you have cleared the concept of blum integers and understand the approach to check if the number is a blum integer or not after reading this article.

Updated on: 21-Jun-2023

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements