Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIHugging Face Arena Human Preference 55K

Write a C++ program to print the first 10,000 prime numbers.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4-0314’s answer.
  1. User

    Write a C++ program to print the first 10,000 prime numbers.

  2. Assistant

    Sure! Here's a C++ program that prints the first 10,000 prime numbers:

    #include <iostream>
    #include <vector>
    
    bool isPrime(int num) {
        if (num < 2) {
            return false;
        }
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
    
    int main() {
        std::vector<int> primes;
        int count = 0;
        int num = 2;
    
        while (count < 10000) {
            if (isPrime(num)) {
                primes.push_back(num);
                count++;
            }
            num++;
        }
    
        for (int prime : primes) {
            std::cout << prime << " ";
        }
    
        return 0;
    }
    

    This program uses a helper function isPrime to check if a number is prime or not. It starts with an empty vector primes to store the prime numbers and a counter count to keep track of the number of prime numbers found. It then uses a while loop to iterate until count reaches 10,000. In each iteration, it checks if the num is prime using the isPrime function, and if it is, it adds it to the primes vector and increments the count variable. Finally, it prints all the prime numbers stored in the primes vector.

    Note that finding the first 10,000 prime numbers can be a computationally expensive task, so the program might take some time to run.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.