Current streak:
0 days
Longest streak:
3 days
Less
More
/*we can find all the divisors of n if we run a loop till the square root of n as we can find two of its divisors at a given i (if n divisible by i) ie i and n/i.
so time complexity: O(sqrt(n))
space complexity O(1)
*/
#include<bits/stdc++.h> using namespace std;
bool checkPrime(int n){ bool flag = true; for(int i=2; i<= sqrt(n); i++){ if(n%i==0 || n%(n/i)==0){ flag = false; break; } } return flag; }
int main() { int n; cin >> n; if(checkPrime(n)) cout << "true"; else cout << "false"; }