From e93b52517e38182a1f5290df492298e5b2e2ada1 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 28 Oct 2022 09:39:07 +0800 Subject: [PATCH] =?UTF-8?q?P3811=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E4=B9=98=E6=B3=95=E9=80=86=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/91843036 --- Luogu/P3811/P3811.cpp | 29 ++++++++++++++++++++--------- Luogu/P3811/data/P3811_3.in | 3 +++ Luogu/P3811/data/P3811_3.out | 3 +++ 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 Luogu/P3811/data/P3811_3.in create mode 100644 Luogu/P3811/data/P3811_3.out diff --git a/Luogu/P3811/P3811.cpp b/Luogu/P3811/P3811.cpp index 3a1f1266..54e2a8fe 100644 --- a/Luogu/P3811/P3811.cpp +++ b/Luogu/P3811/P3811.cpp @@ -1,18 +1,29 @@ -#include +#include -using namespace std; +using std::cin; +using std::cout; +const char endl = '\n'; -long long inv[3000005]; +const int N = 3e6 + 5; + +int n, p, inv[N]; int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> p; + inv[0] = 0; inv[1] = 1; - int n, p; - scanf("%d%d", &n, &p); - printf("1\n"); - for (int i = 2; i <= n; ++i) { - inv[i] = (long long)p - (p / i) * inv[p % i] % p; - printf("%d\n", inv[i]); + + cout << inv[1] << endl; + + for (int i = 2; i <= n; i++) { + inv[i] = p - static_cast(p) / i * inv[p % i] % p; + + cout << inv[i] << endl; } + return 0; } diff --git a/Luogu/P3811/data/P3811_3.in b/Luogu/P3811/data/P3811_3.in new file mode 100644 index 00000000..ad1f8332 --- /dev/null +++ b/Luogu/P3811/data/P3811_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d06f12ebc386aeb5a5facd826cbec052d85905fd17948065b563373ccb22ed11 +size 14 diff --git a/Luogu/P3811/data/P3811_3.out b/Luogu/P3811/data/P3811_3.out new file mode 100644 index 00000000..ac815e7a --- /dev/null +++ b/Luogu/P3811/data/P3811_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:029e1b33f47caa204d41b99ce618366d9ddaea0a34309ea233fdf8648ea5a0d7 +size 75838