variables - Time complexity of this testing algorithm? -
what worst case scenario , how improve while statement?
main() {
clock_t tic = clock(); int n, i, j; int *p; scanf("%d",&n); p=&n; printf("1 \n"); getchar(); for(i=2; i-*p; i++) { j=2; while(j<(int)sqrt((double)i)+1) if(i % j) j++; else j=(int)sqrt((double)i)+3; if(j!=(int)sqrt((double)i)+3) printf("%d \n",i); } clock_t toc = clock(); printf("elapsed: %f seconds\n", (double)(toc - tic) / clocks_per_sec); getchar(); }
Comments
Post a Comment