我正在编写一个小程序来解决 Project Euler Problem 21,当我遇到无法解释的内部编译器错误时,我正在测试我的代码的早期部分。我将不胜感激有关如何重新编写程序以避免此类错误的任何提示。
这是我的构建命令和编译器选项:
g++ -std=c++11 -O2 -Wall -o "pe_021" "pe_021.cc"
这是我得到的错误:
Internal compiler error: Error reporting routines re-entered.
Compilation failed.
这是我的代码:
#include <array>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const unsigned int N = 10000; //look for amicable numbers smaller than N
vector<unsigned int> list_of_primes;
vector<unsigned int[2]> prime_factorize(unsigned int);
int main(int argc, char **argv)
{
//import a list of primes
ifstream ifs ("primes_10000.txt");
for (unsigned int index = 0; index < N; index++) {
string prime_number;
getline(ifs, prime_number);
list_of_primes.push_back(stoi(prime_number));
}
ifs.close();
//test prime factorization function by prime factorizing 12
vector<unsigned int[2]> prime_factorization = prime_factorize(12);
for(unsigned int (&prime_and_exponent)[2] : prime_factorization) {
cout << prime_and_exponent[0] << ", " << prime_and_exponent[1] << endl;
}
return 0;
}
vector<unsigned int[2]> prime_factorize(unsigned int number)
{
vector<unsigned int[2]> prime_factorization;
for(unsigned int index = 1; index < list_of_primes.size(); index++) {
if(number % list_of_primes[index] == 0) {
unsigned int prime_and_exponent[2] = {list_of_primes[index], 1};
prime_factorization.push_back(prime_and_exponent);
number /= list_of_primes[index];
while(number % list_of_primes[index] == 0) {
prime_factorization.back()[1]++;
number /= list_of_primes[index];
}
}
if(number == 1) {
break;
}
}
return prime_factorization;
}