Home  >  Article  >  Backend Development  >  Reconfigurable numbers in C++

Reconfigurable numbers in C++

WBOY
WBOYforward
2023-08-31 18:49:151512browse

Reconfigurable numbers in C++

Given a value of integer type, assuming it is number. The task is to check if a given number is reconfigurable. If so, printing the number is a reconfigurable number, otherwise printing is impossible.

What are reconfigurable numbers?

A number is reconfigurable when it is divisible by the total number of its available factors. For example, the number 9 is reconfigurable because it has 3 factors (1, 3, 9), and 9 is divisible by 3, so it is a reconfigurable number.

Let us take a look at the various input and output situations of this-

Input - int number = 9

Output - This is a reconfigurable number

Explanation - A number is reconfigurable when it is divisible by the total number of its available factors. We are given a number 9, which is reconfigurable because it has 3 factors (1, 3, 9)

9 is divisible by 3, so it is a reconfigurable number.

Input− int number = 10

Output− It is not a Refactorable number

Explanation - A number is reconfigurable when it is divisible by the total number of available factors. We get a number 10, which is not reconfigurable because the total number of its factors is 4(1, 2, 5, 10), and 10 is not divisible by 4, so it is not a reconfigurable number

The method used in the following program is as follows

  • Enter a variable of integer type, such as a number.

  • Pass data to the bool type function check_Refactorable(int number).

  • Internal function check_Refactorable(int number)

    • declares an integer variable with a count of 0.

    • Start looping FOR from i to 1 until i is less than sqrt (number). Inside the loop, you check IF number % i = 0, then IF number / i = i, and then pre-increment the count by 1.

    • ELSE, sets count to count 2 .

    • Returns number % count == 0

  • Print the results.

  • Print the result. p>

  • Example

    #include <bits/stdc++.h>
    using namespace std;
    bool check_Refactorable(int number){
       int count = 0;
       for (int i = 1; i <= sqrt(number); ++i){
          if(number % i==0){
             if(number / i == i){
                ++count;
             }
             else{
                count += 2;
             }
          }
       }
       return number % count == 0;
    }
    int main(){
       int number = 9;
       if(check_Refactorable(number) == 1){
          cout<<"It is a Refactorable number";
       }
       else{
          cout<<"It isn&#39;t a Refactorable number";
       }
       return 0;
    }

    Output

    If we run the above code, it will generate the following output

    It is a Refactorable number

    The above is the detailed content of Reconfigurable numbers in C++. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete