bool f(int x) { if(x==2) return true; if(x<2 || x&1) return false; for(int i=3;i*i<=x;i+=2) if(x%i==0) return false; return true; }
此算法时间复杂度:n2\frac{\sqrt{n}}{2}2n (应该没算错吧) 那这个方法和线型,欧拉或者其它的比哪个比较快?(欧拉和线型时间复杂度网上好多,有n的,有n*log(n)的,不知道哪个是对的)