Submission #18879409


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include <atcoder/math>
#include<bits/stdc++.h>
using namespace atcoder;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ll GCD(ll x, ll y) {
    if (y == 0) {
        return x;
    }
    return GCD(y, x % y);
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#else
//    freopen("lupa.in","r",stdin);
//    freopen("pupa.out","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10);
    cout << fixed;
    int T;
    cin >> T;
    while (--T >= 0) {
        int n, pos, k;
        cin >> n >> pos >> k;
        pos = (n - pos) % n;
        ll gcd = GCD(n, k);
        if (pos % gcd != 0) {
            cout << -1;
        } else {
            n /= gcd;
            k /= gcd;
            pos /= gcd;
            ll ans = pos * inv_mod(k, n);
            ans %= n;
            cout << ans;
        }
        cout << '\n';
    }
    return 0;
}

Submission Info

Submission Time
Task E - Throne
User Paliukh
Language C++ (GCC 9.2.1)
Score 500
Code Size 1088 Byte
Status AC
Exec Time 6 ms
Memory 3648 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 32
Set Name Test Cases
Sample sample_01.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt
Case Name Status Exec Time Memory
hand_01.txt AC 3 ms 3588 KiB
random_01.txt AC 3 ms 3496 KiB
random_02.txt AC 2 ms 3540 KiB
random_03.txt AC 3 ms 3532 KiB
random_04.txt AC 2 ms 3604 KiB
random_05.txt AC 2 ms 3544 KiB
random_06.txt AC 2 ms 3516 KiB
random_07.txt AC 2 ms 3536 KiB
random_08.txt AC 2 ms 3496 KiB
random_09.txt AC 2 ms 3532 KiB
random_10.txt AC 2 ms 3648 KiB
random_11.txt AC 2 ms 3588 KiB
random_12.txt AC 2 ms 3548 KiB
random_13.txt AC 2 ms 3548 KiB
random_14.txt AC 2 ms 3552 KiB
random_15.txt AC 2 ms 3536 KiB
random_16.txt AC 3 ms 3532 KiB
random_17.txt AC 2 ms 3548 KiB
random_18.txt AC 3 ms 3484 KiB
random_19.txt AC 2 ms 3524 KiB
random_20.txt AC 2 ms 3644 KiB
random_21.txt AC 2 ms 3568 KiB
random_22.txt AC 3 ms 3588 KiB
random_23.txt AC 3 ms 3540 KiB
random_24.txt AC 2 ms 3592 KiB
random_25.txt AC 2 ms 3556 KiB
random_26.txt AC 2 ms 3592 KiB
random_27.txt AC 4 ms 3620 KiB
random_28.txt AC 2 ms 3592 KiB
random_29.txt AC 2 ms 3548 KiB
random_30.txt AC 6 ms 3540 KiB
sample_01.txt AC 2 ms 3532 KiB