このコードは 100000 まで完全に機能していますが、1000000 を入力するとエラーが発生し始めますC++ 0xC0000094: Integer division by zero
。浮動小数点に関するものだと確信しています。(/fp:precise)、(/fp:strict)、(/fp:except)、(/fp:except-) のすべての組み合わせを試しましたが、肯定的な結果は得られませんでした。
#include "stdafx.h"
#include "time.h"
#include "math.h"
#include "iostream"
#define unlikely(x)(x)
int main()
{
using namespace std;
begin:
int k;
cout<<"Please enter the nth prime you want: ";
cin>>k;
int cloc=clock();
int*p;p=new int [k];
int i,j,v,n=0;
for(p[0]=2,i=3;n<k-1;i+=2)
for(j=1;unlikely((v=p[j],pow(v,2)>i))?!(p[++n]=i):(i%v);++j);
cout <<"The "<<k<<"th prime is "<<p[n]<<"\nIt took me "<<clock()-cloc<<" milliseconds to find your prime.\n";
goto begin;
}