BS_EXAM_TEST_FINAL3 - Bộ ba số

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Mạng
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, JavaScript, Kotlin, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài


Bình luận

Please read the guidelines before commenting.



  • 0
    nhankiettvt  đã bình luận lúc 22, Tháng 7, 2026, 6:29

    code full ac cho ae

    #include <algorithm>
    #include <bitset>
    #include <climits>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <utility>
    #include <vector>
    
    using namespace std;
    
    #define pii pair&lt;int, int>
    #define pll pair&lt;ll, ll>
    #define vi vector<int>
    #define vll vector<ll>
    #define fi first
    #define se second
    #define pb push_back
    #define all(x) (x).begin(), (x).end()
    #define ll long long
    #define ull unsigned long long
    
    #define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
    #define FORD(i, a, b) for (int i = (a); i >= (b); --i)
    #define REP(i, n) for (int i = 0; i < (n); ++i)
    
    void fast_io() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
    }
    void solve() {}
    vector<int> o;
    bool is_nguyen_to(int n) {
      if (n < 2)
        return 0;
      for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)
          return 0;
      }
      return 1;
    }
    void b() {
      for (int i = 2; i <= 100000; i++) {
        if (is_nguyen_to(i)) {
          o.push_back(i);
        }
      }
    }
    int main() {
      fast_io();
      int k;
      cin >> k;
      ull dem = 0;
      b();
      ull n = o.size();
      if (k <= 100) {
        for (int i = 0; i <= k; i++) {
          for (int j = i; j <= k; j++) {
            for (int z = j; z <= k; z++) {
              if (i + j + z == k && is_nguyen_to(i) && is_nguyen_to(j) &&
                  is_nguyen_to(z)) {
                dem++;
              }
            }
          }
        }
      } else {
        for (int i = 0; i < n; i++) {
          for (int j = i; j < n; j++) {
            if (k - (o[i] + o[j]) > 0 && is_nguyen_to(k - (o[i] + o[j])) &&
                o[i] <= o[j] && o[j] <= k - (o[i] + o[j])) {
              dem++;
            }
          }
        }
      }
      cout << dem;
      return 0;
    }
    

  • -1
    nhatminecraftthanhgu  đã bình luận lúc 24, Tháng 4, 2026, 2:43

    code cho ae:

    include <bits/stdc++.h>

    using namespace std;

    const int N = 100000; bool isPrime[N + 1];

    void sieve() { fill(isPrime, isPrime + N + 1, true); isPrime[0] = isPrime[1] = false;

    for (int i = 2; i * i <= N; i++) {
        if (isPrime[i]) {
            for (int j = i * i; j <= N; j += i)
                isPrime[j] = false;
        }
    }
    

    }

    int main() { ios::syncwithstdio(false); cin.tie(nullptr);

    int k;
    cin >> k;
    
    sieve();
    
    int ans = 0;
    
    for (int x = 2; x <= k; x++) {
        if (!isPrime[x]) continue;
    
        for (int y = x; y <= k; y++) {
            if (!isPrime[y]) continue;
    
            int z = k - x - y;
            if (z < y) break;
            if (z > N) continue;
    
            if (isPrime[z]) ans++;
        }
    }
    
    cout << ans;
    return 0;
    

    }