Created
August 26, 2016 09:04
-
-
Save oskimura/f284b19f27ddadb450e1247785db9835 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <vector> | |
#include <assert.h> | |
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
bool isprime(int n) | |
{ | |
assert(n>0); | |
if (n==1) { | |
return false; | |
} | |
assert(n>1); | |
if (n==2) { | |
return true; | |
} | |
assert(n>2); | |
if (n%2==0) { | |
return false; | |
} | |
for (int i=3; i<=pow(n,1.0/2.0); i=i+2) { | |
if(n%i == 0.0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
int main () | |
{ | |
assert(isprime(1) == false); | |
assert(isprime(2) == true); | |
assert(isprime(3) == true); | |
assert(isprime(4) == false); | |
assert(isprime(5) == true); | |
assert(isprime(7) == true); | |
assert(isprime(11) == true); | |
int n; | |
cin >> n; | |
int cnt=0; | |
for (int i=0; i<n; i++) { | |
int m; | |
cin >> m; | |
if (isprime(m)) { | |
cnt++; | |
} | |
} | |
cout << cnt << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment