Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:48:27+00:00 2026-05-27T13:48:27+00:00

is there any way to convert this to a recursion form? how to find

  • 0

is there any way to convert this to a recursion form?
how to find the unknown prime factors(in case it is a semiprime)?

semiPrime function:

bool Recursividad::semiPrimo(int x)
{
    int valor = 0;
    bool semiPrimo = false;
    if(x < 4)
    {
        return semiPrimo;
    }
    else if(x % 2 == 0)
    {
        valor = x / 2;
        if(isPrime(valor))
        {
            semiPrimo = true;
        }
    }
    return semiPrimo;
}

Edit: i’ve come to a partial solution(not in recursive form). i know i have to use tail recursion but where?

   bool Recursividad::semiPrimo(int x){
    bool semiPrimo=false;
vector<int> listaFactores= factorizarInt(x);
vector<int> listaFactoresPrimos;
int y = 1;

for (vector<int>::iterator it = listaFactores.begin();
            it!=listaFactores.end(); ++it) {
                if(esPrimo(*it)==true){
            listaFactoresPrimos.push_back(*it);         
        }
    } 
int t=listaFactoresPrimos.front();
if(listaFactoresPrimos.size()<=1){  
    if(t*t==x){
    semiPrimo=true;
    }
}else{
    int f=0;
    #pragma omp parallel 
    {
     #pragma omp for
    for (vector<int>::iterator it = listaFactoresPrimos.begin();
            it!=listaFactoresPrimos.end(); ++it) {
                f=*it;
                int j=0;
                for (vector<int>::iterator ot = listaFactoresPrimos.begin();
            ot!=listaFactoresPrimos.end(); ++ot) {
                j=*ot;

                if((f * j)==x){
                            semiPrimo=true;         }

                }

    } 
    }
}
return semiPrimo;
}

any help would be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:48:28+00:00Added an answer on May 27, 2026 at 1:48 pm

    You can convert a loop into recursion in a formulaic manner. Note that do_something() needn’t be a single function call; it can be anything (except flow control like break that’d change the loop behavior):

    void iterative() {
        for (int x = 0; x < 10; ++x) {
            do_something(x);
        }
    }
    

    becomes

    void recursion_start() {
        recursive(0);
    }
    
    void recursive(int x) {
        if (x < 10) {
            do_something(x);
            recursive(x + 1);
        }
    }
    

    Note also that you can rewrite that as the following, which in a good compiler will actually run just as fast as the iterative version (this is called “tail-call optimization”). gcc 4.6.2, for example, manages to do this—actually, its smart enough to do the above version as well.

    void recursive(int x) {
        if (x >= 10)
            return;
        do_something(x);
        recursive(x + 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe this is a dumb question, but is there any way to convert a
hey all, is there any way to convert a given file (this could be
Is there any way, how to convert this: namespace Library { public struct Content
Is there any way to convert a bmp image to jpg/png without losing the
Is there any way to convert from DB.Null to decimal in C#? Like Object[]
Is there any way to convert differential backup to SQL statements which will produce
Is there any way to convert from toString back to the object in Java?
Is there any good way convert a binary (base 2) strings to integers in
Simple question here: is there any way to convert from a jagged array to
Is there any way we can convert text to speech in an iPhone app?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.