6 solutions
-
1
#include<iostream> #include<cmath> using namespace std; bool isPrime(int num); int main(){ int n; cin >> n; for(int i = 1; i <= n; i++){ int x; cin >> x; if(isPrime(x)) cout << "Yes" << endl; else cout << "No" << endl; } return 0; } bool isPrime(int num){ if(num <= 3) return num > 1; if(num%6 != 1 && num%6 != 5) return false; int y = (int) sqrt(num); for(int i = 5; i <= y; i += 6){ if(num%i == 0 || num%(i+2) == 0) return false; } return true; }
Information
- ID
- 43
- Time
- 5000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 1242
- Accepted
- 247
- Uploaded By