QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100 Difficulty: [show] Interactive

#5. Online Multiplicative Inverse Query

Statistics

Problem Description

You are given $n$ queries. For each query, you are given an integer $x$, and you need to calculate the multiplicative inverse of $x$ in $\mathbb{F}_{998\,244\,353}$. In other words, you need to find the integer $y \in [0, 998\,244\,353)$ where $x \cdot y \equiv 1 \pmod {998\,244\,353}$.

You have to answer all queries online.

Implementation Details

You need to include the file inv.h and implement the following functions:

void init(int p)
  • p denotes the modulus in this problem, which will always be $998\,244\,353$.
  • The function will be called exactly one at the beginning of each test case.
int inv(int x)
  • x is the number given in this query.
  • You need to return the multiplicative inverse of $x$ in $\mathbb F_{998\,244\,353}$.

The function inv will be called exact $n$ times.

Scoring

For all test cases, $1 \leq n \leq 10^8$, $p = 998\,244\,353$.

  • Subtask 1(10 Points): $n \leq 10^5$
  • Subtask 2(20 Points): $n \leq 10^7$
  • Subtask 3(30 Points): $n \leq 5 \times 10^7$
  • Subtask 4(20 Points): $n \leq 8 \times 10^7$
  • Subtask 5(20 Points): No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.