QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#481327#5. 在线 O(1) 逆元GoatGirl98#Compile Error//C++172.2kb2024-07-17 01:32:242024-11-05 22:01:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 22:01:36]
  • 管理员手动重测本题所有提交记录
  • [2024-07-17 01:32:25]
  • 评测
  • [2024-07-17 01:32:24]
  • 提交

answer

#include "inv.h"
const int mod = 998244353;
namespace modulo
{
    int add(int a, int b) { return (a + b >= mod) ? (a + b - mod) : (a + b); }
    int sub(int a, int b) { return (a < b) ? (a - b + mod) : (a - b); }
    int mul(int a, int b) { return 1ll * a * b % mod; }
    int qpow(int x, int p)
    {
        int ans = 1;
        while (p)
        {
            if (p & 1)
                ans = mul(ans, x);
            x = mul(x, x);
            p >>= 1;
        }
        return ans;
    }
    // n = p^(1/3)
    const int n = 1000, m = n * n, lim = mod / n;
    const int maxn = n + 5, maxm = m + 5, maxl = lim + 5;
    int sum[maxm], frac[maxm], N, F[maxm];
    int cp, p[maxl], I[maxl];
    bool np[maxl];
    void build()
    {
        for (int q = 1; q < n; ++q)
            for (int p = 0; p <= q; ++p)
            {
                int i = p * m / q;
                if (!sum[i])
                    sum[i] = 1, frac[i] = p * n + q;
            }
        for (int i = 1; i <= m; ++i)
            sum[i] += sum[i - 1];

        for (int i = 0; i <= m; ++i)
            if (frac[i])
                F[N++] = frac[i];
        I[1] = 1;
        for (int i = 2; i <= lim; ++i)
        {
            if (!np[i])
                p[cp++] = i, I[i] = qpow(i, mod - 2);
            int k;
            for (int j = 0; j < cp && (k = i * p[j]) <= lim; j++)
            {
                np[k] = 1, I[k] = mul(I[i], I[p[j]]);
                if (i % p[j] == 0)
                    break;
            }
        }
    }
    int inv(int a)
    {
        int i = 1ll * a * m / mod, k = sum[i];
        i64 f, t;
        int p, q;
        if (k < N)
        {
            f = F[k], p = f / n, q = f - p * n;
            t = 1ll * a * q - 1ll * p * mod;

            if (std::abs(t) <= lim)
                return mul(q, t > 0 ? I[t] : mod - I[-t]);
        }
        if (--k >= 0)
        {
            f = F[k], p = f / n, q = f - p * n;
            t = 1ll * a * q - 1ll * p * mod;
            if (abs(t) <= lim)
                return mul(q, t > 0 ? I[t] : mod - I[-t]);
        }
        return -1;
    }
}
void init(int p) { modulo::build(); }
int inv(int x) { return modulo::inv(x); }

详细

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code: In function ‘int modulo::inv(int)’:
answer.code:58:9: error: ‘i64’ was not declared in this scope
   58 |         i64 f, t;
      |         ^~~
answer.code:62:13: error: ‘f’ was not declared in this scope
   62 |             f = F[k], p = f / n, q = f - p * n;
      |             ^
answer.code:63:13: error: ‘t’ was not declared in this scope
   63 |             t = 1ll * a * q - 1ll * p * mod;
      |             ^
answer.code:65:22: error: ‘abs’ is not a member of ‘std’
   65 |             if (std::abs(t) <= lim)
      |                      ^~~
answer.code:70:13: error: ‘f’ was not declared in this scope
   70 |             f = F[k], p = f / n, q = f - p * n;
      |             ^
answer.code:71:13: error: ‘t’ was not declared in this scope
   71 |             t = 1ll * a * q - 1ll * p * mod;
      |             ^
answer.code:72:17: error: ‘abs’ was not declared in this scope
   72 |             if (abs(t) <= lim)
      |                 ^~~