diff --git a/General/Prime.cpp b/General/Prime.cpp index 6ede07e..05079a8 100644 --- a/General/Prime.cpp +++ b/General/Prime.cpp @@ -8,8 +8,12 @@ int main() cout << "Enter a positive integer: "; cin >> n; + + //factors exist in pair,so traversing till sqrt(n) to reduce time complexity + //Time Complexity: O(sqrt(n)) + //Space Complexity:O(1) - for(i = 2; i <= n / 2; ++i) + for(i = 2; i*i<=n; i++) { if(n % i == 0) {