We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;voidcheckPrime(intn){if(n==2){cout<<"Prime"<<endl;return;}if(n%2==0||n==1){cout<<"Not prime"<<endl;return;}for(inti=3;i<=n/i;i+=2){if(n%i==0){cout<<"Not prime"<<endl;return;}}cout<<"Prime"<<endl;}intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intT,n;cin>>T;while(T--){cin>>n;checkPrime(n);}return0;}
Cookie support is required to access HackerRank
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 →
C++ Solution