/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 3ms 540.0 KiB
#4 Accepted 4ms 576.0 KiB
#5 Accepted 7ms 560.0 KiB
#6 Accepted 9ms 564.0 KiB
#7 Accepted 11ms 632.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 2ms 332.0 KiB
#10 Accepted 2ms 332.0 KiB
#11 Accepted 3ms 336.0 KiB
#12 Accepted 11ms 540.0 KiB
#13 Accepted 1ms 440.0 KiB
#14 Accepted 1ms 540.0 KiB
#15 Accepted 1ms 540.0 KiB
#16 Accepted 1ms 328.0 KiB
#17 Accepted 1ms 540.0 KiB
#18 Accepted 1ms 540.0 KiB
#19 Accepted 1ms 540.0 KiB
#20 Accepted 1ms 400.0 KiB
#21 Accepted 1ms 548.0 KiB

Code

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;

bool isPrime(ll n) { // O(sqrt(n))
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    vector<int> prime;
    for(int i = 2; i <= 1000; i++) {
        if(isPrime(i)) prime.push_back(i);
    }
    int x, ans = 0;
    cin >> x;
    for(int a = 1; a <= x; a++) {
        for(int b = 1; b <= x; b++) {
            if(a + b + 1 > x) break;
            auto it1 = upper_bound(prime.begin(), prime.end(), a + b);
            auto it2 = upper_bound(prime.begin(), prime.end(), x);
            ans += it2 - it1;
        }
    }
    cout << ans << endl;
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1172 Counting Triplets
Contest
Lu IEEE testing round
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-24 21:05:54
Judged At
2025-02-24 21:06:24
Judged By
Score
100
Total Time
11ms
Peak Memory
632.0 KiB