Problem:
Prime Numbers
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
Write a program which reads a list of
N
integers and prints the number of prime numbers in the list.
Input
The first line contains an integer
N
, the number of elements in the list.
N
numbers are given in the following lines.
Output
Print the number of prime numbers in the given list.
Constraints
1 ≤
N
≤ 10000
2 ≤
an element of the list
≤ 10
8
Sample Input 1
5
2
3
4
5
6
Sample Output 1
3
Sample Input 2
11
7
8
9
10
11
12
13
14
15
16
17
Sample Output 2
4

Submitted solutions:

code_snippet: #include<bits/stdc++.h> 
using namespace std;
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int main(){
      ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t ; 
        cin>>t;
        int result = 0 ;
       for(int i = 0 ; i < t ; i++){
            long long n ; 
            cin>>n;
            if(n==2 || n==3 || n==5 || n==7 || n==11 ){
                result++;
                continue;
            }
            else if(n<2){
                continue;
            }
            else if(n%2==0 || n%3==0 || n%5==0 || n%7==0 || n%11==0){
                continue;
            }
            else{
                for(int i = 13 ; i*i <= n ; i+=2){
                    if(n%i==0){
                        result--;
                        break;
                    }
                }
            }
            result++;
        }
        cout<<result<<"\n";
        }
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 16

code_snippet: #include <stdio.h>
int main()
{
    int n,c=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0; i<n;i++)
    {
        scanf("%d",&a[i]);
        int p=1;
        if(a[i]<2)
        {
            p=0;
        }
        for(int j=2; j*j<=a[i]; j++)
       {
        if(a[i]%j==0)
        {
            p=0;
            break;
        }
       }
       if(p==1)
       {
           c++;
       }
    }
       printf("%d\n",c);

    return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 2992
final_rank: 1

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	int t = 0;

	for (int i = 0; i < n; i++) {
		int a;
		int b = 1;
		bool isPrime =true;
		cin >> a;
		while (b < sqrt(a - 1)) {
			b++;
			if (a % b == 0) {
				isPrime = false;
				break;
			}
		}
		if (isPrime==true) {
			t++;
		}
	}
	cout<<t<<endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3436
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;

bool isPrime(int x){
    if(x<=1)return false;
    if(x==2)return true;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
int main(){
    int count = 0;
    int n; cin >> n;
    for(int i=0;i<n;i++){
        int m;
        cin >> m;
        if(isPrime(m)){
            count+=1;
        }
    }
    cout << count << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    
    int ans = 0;
    for (int i=0; i<n; i++)
    {
        long long tmp;
        cin >> tmp;
        bool isPrime = (tmp%2 == 0 && tmp != 2)? false : true;
        if (isPrime)
        {
            long long lim = sqrt(tmp);
            for (int i=3; i<=lim; i+=2)
            {
                if (tmp%i == 0)
                {
                    isPrime = false;
                    break;
                }
            }
        }
        if (isPrime)
            ans++;
    }
    cout << ans << "\n";
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 13

code_snippet: #include <iostream>

using namespace std;

int is_prime(int n) {
    
    if (n == 2) return 1;

    else if (!(n % 2)) return 0;
    
    // 合成数の判定
    int i = 3;
    
    while (i * i <= n) {
        if (!(n % i)) return 0;
        i++;// 3 --> 5 --> 7 .......
    }
    return 1;

}

int main() {
    
    int n,p_count = 0;
    cin >> n;

    int no[n];

    for (int i = 0;i < n;i++) {
        cin >> no[i];
        p_count += is_prime(no[i]);
    }

    cout << p_count << endl;

}
accuracy: 1
time_ms: 10
memory_kb: 3372
final_rank: 11

code_snippet: #include <iostream>
#include <vector>

static const int MAX = 1000000;

std::vector<bool> sieve(int limit) {
    std::vector<bool> is_prime(limit + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= limit; ++i) {
        if (is_prime[i]) {
            for (int j = i * i; j <= limit; j += i)
                is_prime[j] = false;
        }
    }
    return is_prime;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> X(n);
    for (int i = 0; i < n; ++i) std::cin >> X[i];

    int max_val = 0;
    for (int x : X) if (x > max_val) max_val = x;
    auto is_prime = sieve(max_val);

    int count = 0;
    for (int x : X)
        if (x >= 2 && is_prime[x]) ++count;

    std::cout << count << "\n";
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 15360
final_rank: 20

code_snippet: #include<iostream>
#include<cmath>
using namespace std;

int isprime(int);

int main(){
    int n, total, i;
    int num[10'000];
    cin >> n;

    total = 0;
    for(i = 0; i < n; i++){
        cin >> num[i];

        total += isprime(num[i]);
    }
    cout << total << endl;
    return 0;
}

int isprime(int n){
    int i;

    if(n == 2) return 1;
    else if(n == 1 or n%2 == 0) return 0;
    else{
        for(i = 3; i <= sqrt(n); i++){
            if(n%i == 0) return 0;
        }
        return 1;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3444
final_rank: 15

code_snippet: #include<iostream>
#include<cmath>
using namespace std;
int main(void){
    int c,cnt=0,t=0;
    while(cin>>c){
        if(c%2==0 or c==1){
            if(c!=2){
                cnt++;
            }
        }
        else{for(int i=3;i<=sqrt(c);i+=2){
            if(c%i==0){
                cnt++;
                break;
            }
        }
        }
        
        t++;
    }
    cout<<t-cnt<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool is_prime(int N){
    for (int i = 2; i*i <= N; i++) if (N%i == 0) return false;
    return true;
}

int main(){
    int N, A, count = 0;
    cin >> N;
    
    for (int _ = 0; _ < N; _++){
        cin >> A;
        if (is_prime(A)) count++;
    }
    
    cout << count << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 7

code_snippet: using namespace std;
#include <iostream>
#include <vector>

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];

    int c = 0;
    for (int i = 0; i < n; ++i) {
        if (x[i] < 2) continue; 
        bool prime = true;
        for (int j = 2; j * j <= x[i]; ++j) {
            if (x[i] % j == 0) {
                prime = false;
                break;
            }
        }
        if (prime) c += 1;
    }

    cout << c << "\n";
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 13

code_snippet: #include <iostream>
using namespace std;

bool isPrime(int x){
    if (x < 2) return false;
    for (int i = 2; i*i <= x; i++){
        if (x % i == 0) return false;
        //else return true; これやるとbreakと同じになってしまう
    }
    return true;
}

int main(){
    int N; cin >> N;
    int ans = 0;
    int V[N];
    for (int i = 0; i < N; i++) cin >> V[i];
    for (int i = 0; i < N; i++) if (isPrime(V[i])) ans++;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 6

code_snippet: #include <iostream>
using namespace std;

int main(){
    int N; cin >> N;
    int V[N];
    int ans = 0;
    for (int i = 0; i < N; i++){
        cin >> V[i];
        
        for (int j = 2; j * j <= V[i]; j++){
            if (V[i] % j == 0){
                ans += 1;
                break;
            }
        }      
    }
    cout << N - ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 4

code_snippet: #include<iostream>
#include<cmath>
using namespace std;

int isDigit(int);

int main(){
    int n, check, i;
    int num[10000];
    int count = 0;
    cin >> n;
    for(i = 0; i < n; i++) cin >> num[i];

    for(i = 0; i < n; i++){
        check = isDigit(num[i]);
        count += check;
    }

    cout << count << endl;
    return 0;
}

int isDigit(int n){
    int i;
    if(n == 2) return 1;
    else if(n == 1 or n%2 == 0) return 0;
    else{
        for(i = 3; i <= sqrt(n); i++){
            if(n%i == 0) return 0;
        }

        return 1;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3404
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


// vectorを出力する
void vec1print(vector<ll> vec) {
    rep(i, vec.size()) {
        cout << vec[i] << endl;
    }
}
void vec2print(vector<ll> vec) {
    rep(i, vec.size()) {
        cout << vec[i] << " ";
    }
    cout << endl;
}

// 最大か最小を求める
int minval(vector<ll> vec) {
    return *min_element(begin(vec), end(vec));
}
int maxval(vector<ll> vec) {
    return *max_element(begin(vec), end(vec));
}

// グリット用
vector<ll> dx = {1, 0, -1, 0};
vector<ll> dy = {0, 1, 0, -1};
bool in_grid(ll x, ll y, ll limit_x, ll limit_y) {
    return 0 <= x and x < limit_x and 0 <= y and y < limit_y;
}

// main
void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,n) {
        ll x;
        cin >> x;
        bool ok = true;
        ll root_x = sqrt(x);
        for (ll i = 2; i <= root_x; ++i) {
            if (x % i == 0) {
                ok =false;
            }
        }
        if (ok) ans += 1;
    }
    cout << ans << endl;

    return;
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3456
final_rank: 19

code_snippet: #include<iostream>
#include<cmath>
using namespace std;

int isprime(int);

int main(){
    int n, x, check, i, j;
    int count = 0;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x;
        check = isprime(x);
        if(check == 1) count++;
    }
    cout << count << endl;
    return 0;
}

int isprime(int x){
    int i;
    if(x == 2) return 1;
    else if(x == 1 or x%2 == 0) return 0;
    else{
        for(i = 3; i <= sqrt(x); i++){
            if(x%i == 0) return 0;
        }
        return 1;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 4

code_snippet: #include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n, num = 0, count = 0; cin >> n;
    for(int i=0;i<n;i++){
        bool flag  = true;
        cin >> num;
        int sqrt_num = sqrt(num);
        for(int j=2;j<=sqrt_num;j++){
            if(num % j == 0){
                flag = false;
                break;
            }
        }
        if(flag == true){
            count++;
        }
    }
    cout << count << endl;    
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int is_prime(int n) {
    if (n <= 1) return 0;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n;
    int ans = 0;
    cin >> n;
    vector<int> primes(n);
    for (int i = 0; i < n; i++) {
        cin >> primes[i];
    }
    for (int i = 0; i < n; i++) {
        if (is_prime(primes[i])) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 10

code_snippet: //
//  main.cpp
//  MyCp
//
//  Created by 今井青波 on 2025/08/27.
//

// ===== begin my_bits.hpp =====
//
//  my_bits.hpp
//  MyCp
//
//  Created by 今井青波 on 2025/08/28.
//

#pragma once
#include <bits/stdc++.h>
using namespace std;

// ---------------- macro ----------------
#define rep(i,x,limit) for (int i = (int)x; i < (int)limit; i++)
#define REP(i,x,limit) for (int i = (int)x; i <= (int)limit; i++)
#define repd(i,x,limit) for (int i = (int)x; i > (int)limit; i--)
#define REPD(i,x,limit) for (int i = (int)x; i >= (int)limit; i--)
#define ifRange(x,a,b) if (x>=a && x<=b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa " "
#define Yes cout << "Yes" << el
#define No cout << "No" << el
#define YES cout << "YES" << el
#define NO cout << "NO" << el
#define eps (1e-10)
#define Equals(a,b) (fabs((a) - (b)) < eps )
#ifdef DEBUG
#define debug(x) cerr << "----- DEBUG -----  " << #x << " = " << x << el
#else
#define debug(x)
#endif

inline void setup_io(bool input=true) {
    // spped up cin/cout
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // local only
#ifdef DEBUG
    cerr << "----- INFO -----  Hello world at Src!" << el;
    filesystem::path currentPath = filesystem::current_path();
    cerr << "----- INFO -----  Current directory: " << currentPath.string() << el;
    if (input) {
        freopen("input.in", "r", stdin);
        cerr << "----- INFO -----  input.in read!" << el;
    }
#endif
}

// ---------------- type alias ----------------
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// ---------------- numbers/ strings ----------------
const double pi = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

// ===== end my_bits.hpp =====

int main() {
    setup_io(); // (false): not open input.txt
    
    // insert code here...
    int n,a, cnt=0;cin>>n;
    rep(i,0,n) {
        cin>>a;debug(a);
        if (a%2==0) {
            if(a==2) cnt++;
            continue;
        }
        int j=3;
        bool b=true;
        while (j<=sqrt(a)) {
            if(a%j==0) {
                b=false;
                break;
            }
            j+=2;
        }
        if(b) cnt++;
    }
    cout<<cnt<<el;
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N,n,a =0;
    cin >> N;
    bool b =1;
    for (ll i = 0; i < N; i++) {
        cin >> n;
        for (ll j = 2;j*j <= n;j++) {
            if (n%j == 0) {
                b = 0;
                break;
            }
        }
        if (b) {
            a++;
        }else {
            b = 1;
        }
    }
    cout << a << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3412
final_rank: 18