/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 9ms 544.0 KiB
#3 Accepted 26ms 540.0 KiB
#4 Accepted 46ms 556.0 KiB
#5 Accepted 91ms 540.0 KiB
#6 Accepted 164ms 588.0 KiB
#7 Accepted 202ms 540.0 KiB
#8 Accepted 2ms 540.0 KiB
#9 Accepted 5ms 564.0 KiB
#10 Accepted 5ms 540.0 KiB
#11 Accepted 13ms 540.0 KiB
#12 Accepted 207ms 552.0 KiB
#13 Accepted 1ms 540.0 KiB
#14 Accepted 1ms 540.0 KiB
#15 Accepted 1ms 332.0 KiB
#16 Accepted 1ms 540.0 KiB
#17 Accepted 1ms 540.0 KiB
#18 Accepted 1ms 772.0 KiB
#19 Accepted 1ms 540.0 KiB
#20 Accepted 1ms 616.0 KiB
#21 Accepted 1ms 540.0 KiB

Code

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

bool isitPrime(int n)//time complexity=O(sqrt(n))
{
  if(n==1)return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}

void solve()
{
    
    int n, m;
    cin >> n;
    vector<int>prime;
    for(int i = 3; i <= n; i++)
    {
        if(isitPrime(i))prime.push_back(i);
    }
    int ans = 0;
    for(int a = 1; a < n; a++)
    {
        for(int b = 1; b < n; b++)
        {
            for(auto it : prime)
            {
                int c = it - (a + b);
                if(a + b + c > n || c <= 0)
                {
                    continue;
                }
                ans++;
            }
        }
    }
    cout << ans << endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);cin.tie(0),cin.tie(0);
    int t = 1;
    // cin >> t;
    for (int tc = 1; tc <= t; ++tc)
    {
        // cout << "Case " << tc << ": ";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1172 Counting Triplets
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-26 17:25:12
Judged At
2025-02-26 17:25:12
Judged By
Score
100
Total Time
207ms
Peak Memory
772.0 KiB