2 条题解

  • 0
    @ 2025-10-8 16:48:24

    G15 威尔逊定理

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long LL;
    const int N = 1000001;
    const int mx = 3000008;
    int s[N], p[N], vis[mx], t, n;
    
    void get_prim()
    {
        for (LL i = 2; i < mx; ++i)
            if (!vis[i])
            {
                if ((i - 7) % 3 == 0)
                    p[(i - 7) / 3] = 1;
                for (LL j = i * i; j < mx; j += i)
                    vis[j] = 1;
            }
    }
    int main()
    {
        get_prim();
        for (int i = 2; i < N; ++i)
            s[i] = s[i - 1] + p[i];
        scanf("%d", &t);
        while (t--)
        {
            scanf("%d", &n);
            printf("%d\n", s[n]);
        }
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:48:15

      G15 威尔逊定理

      #include <bits/stdc++.h>
      using namespace std;
      
      typedef long long LL;
      const int N = 1000001;
      const int mx = 3000008;
      int s[N], p[N], vis[mx], t, n;
      
      void get_prim()
      {
          for (LL i = 2; i < mx; ++i)
              if (!vis[i])
              {
                  if ((i - 7) % 3 == 0)
                      p[(i - 7) / 3] = 1;
                  for (LL j = i * i; j < mx; j += i)
                      vis[j] = 1;
              }
      }
      int main()
      {
          get_prim();
          for (int i = 2; i < N; ++i)
              s[i] = s[i - 1] + p[i];
          scanf("%d", &t);
          while (t--)
          {
              scanf("%d", &n);
              printf("%d\n", s[n]);
          }
          return 0;
      }
      • 1

      信息

      ID
      86
      时间
      1000ms
      内存
      162MiB
      难度
      5
      标签
      递交数
      140
      已通过
      58
      上传者