Hackerrank | 30 days of code | Day 11-Solution in c++| Running-Time-and-Complexity-hackerrank-Solution-in-c++


Hackerrank | 30 days of code | Day 25-Solution in c++| Running-Time-and-Complexity-hackerrank-Solution-in-c++

Hackerrank Solution 30-days-of-code


https://www.hackerrank.com/challenges/30-running-ime-and-omplexity/problem
Day 25 Running Time and Complexity Solution in Cpp
#include <iostream> #include <vector> #include <cmath> #include <cstdio> #include <algorithm> using namespace std; bool primeornot(int n) { int i ,sqr; if(n == 1) { return false; } if(n == 2) { return true; } sqr = sqrt(n); for(i = 2; i <= sqr; ++i ) { if(n % i == 0) { return false; } } return true; } int main() { int n, i; bool f; cin >> n; vector arr(n); for(i = 0; i < n; ++i) { cin >> arr[i]; bool f = primeornot(arr[i]); if(f) { cout<<"Prime"<<endl; } else { cout<<"Not prime"<<endl; } } return 0; }

Post a Comment

0 Comments