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.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.