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

  • Home
  • SEARCH
  • 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 9182469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:34:01+00:00 2026-06-17T18:34:01+00:00

I’m working on a problem that asks to generate a sequence using prime numbers

  • 0

I’m working on a problem that asks to generate a sequence using prime numbers 2, 3, and 5, and then displaying then nth number in the sequence. So, if I ask the program to display the 1000th number, it should display it.

I can’t be using arrays or anything like that, just basic decisions and loops.

I started working on it and hit a wall… here’s what I got:

#include <iostream>

using namespace std;
int main() {
    unsigned int n=23;
    for(int i=2; i<n; i++){
        if(i%2==0){
            cout<<i<<", ";
        }else if(i%3==0){
            cout<<i<<", ";
        }else if(i%5==0){
            cout<<i<<", ";
        }
    }

    return 0;
}

Unfortunately, that code doesn’t do what’s required. It displays numbers such as 14, which includes a prime number 7…. The numbers can only be divided by the 3 specified primes (2,3,5).

I found some information that I’m trying to understand, and so far not sure how to implement it… maybe using lots of for() loops? So, it appears I have to use the concept of 2^n * 3^m * 5^k where n+m+k>0.

I guess I have to run a number through a test where it checks to see first if it’s fully divisible by 2^1 * 3^0 * 5^0, then 2^0 * 3^1 * 5^0, then 2^0 * 3^0 * 5^1, and so on… Just not sure where to begin.

  • 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-06-17T18:34:02+00:00Added an answer on June 17, 2026 at 6:34 pm

    Check this.

    #include <iostream>
    using namespace std;
    
    int IsPrime(int var);
    int CheckifPrimeGreaterThaFive(int Num);
    int GetFactors(int Num)
    {
        int i =0,j=0;
        for (i =2,j=0; i <= Num; i++)
        {
            if (Num%i == 0)
            {
               if (1 == CheckifPrimeGreaterThaFive(i))
               {
                     return 1;
                  }
            }
        }
        return 0;
    }
    
    int CheckifPrimeGreaterThaFive(int Num)
    {
       if ((Num != 2 && Num != 3 && Num != 5) && IsPrime(Num))
       {
    
               return 1;
       }
    
        return 0;
    }
    
    int IsPrime(int var)
    {
        for (int i = 2; i <= var/2; i++)
        {
            if (var % i == 0)
               return 0;
        }
        return 1;
    }
    
    
    int main() {
        int n=98;
        int i, FactorsCount=0;
    
        for(i=2; i<n; i++)
        {
            if (0 == GetFactors(i))
            {  
               cout<<" "<<i;
            }   
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.