For the USACO training gateway exercise humble numbers, I have a solution that works for the first 4 test cases, but then for test case 5 which has been supplied below to circumvent the need for input files, my program gets the correct answer locally when compiled by GCC and on my phone ( not sure what compiler). If I submit the answer to USACO it does not give the correct answer. From what I read that means the program has some undefined behaviour somewhere, but I could not find anything.
#include <fstream>
#include <iostream>
#include <set>
using namespace std;
//ifstream fin("humble.in");
//ofstream fout("humble.out");
set<unsigned long> cont;
int main() {
int K = 6;
int N = 25000;
unsigned long values[]= {2, 3, 5, 7, 11, 13};
cont.insert(1);
unsigned long r = 0;
for (int i = 0; i <= N; i++) {
r = *cont.begin();
for (int j = 0; j < K; j++)
cont.insert(r*values[j]);
cont.erase(r);
}
cout << r << endl;
return 0;
}
The answer I get locally (and the correct answer) is 682628310. The answer I get on USACO is 67108864.