You are viewing a single comment's thread. Return to all comments →
My C solution
int t; scanf("%d", &t); int n; for(int i = 0 ; i < t ; i++){ scanf("%d", &n); if((n % 2 == 0 && n != 2) || n == 1){ printf("Not prime\n"); } else{ int isPrime = 1; for(int i = 3 ; i <= n/2 ; i+=2){ if(n % i == 0){ isPrime = 0; break; } } if(isPrime) printf("Prime\n"); else printf("Not prime\n"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
My C solution