結果

問題 No.551 夏休みの思い出(2)
ユーザー 259_Momone259_Momone
提出日時 2017-07-29 00:02:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 4,000 ms
コード長 1,949 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 160,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 13:44:48
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 41 ms
5,376 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 39 ms
5,376 KB
testcase_30 AC 41 ms
5,376 KB
testcase_31 AC 31 ms
5,376 KB
testcase_32 AC 41 ms
5,376 KB
testcase_33 AC 37 ms
5,376 KB
testcase_34 AC 40 ms
5,376 KB
testcase_35 AC 33 ms
5,376 KB
testcase_36 AC 36 ms
5,376 KB
testcase_37 AC 39 ms
5,376 KB
testcase_38 AC 46 ms
5,376 KB
testcase_39 AC 39 ms
5,376 KB
testcase_40 AC 40 ms
5,376 KB
testcase_41 AC 43 ms
5,376 KB
testcase_42 AC 39 ms
5,376 KB
testcase_43 AC 38 ms
5,376 KB
testcase_44 AC 38 ms
5,376 KB
testcase_45 AC 36 ms
5,376 KB
testcase_46 AC 46 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%lld%lld%lld", &P, &R, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%lld%lld%lld", &A, &B, &C);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long int P, R, Q, A, B, C, D, x, y, it;

static inline long long mdp(long long int a, long long int n){
    long long int r = 1;
    while(n){
        if(n & 1)r = r * a % P;
        a = a * a % P;
        n /= 2;
    }
    return r;
}

static inline long long pmdp(long long a, long long b){
    long long int r = 1, s = 0, i1, i2, ro = a, n = (P + 1) / 2;
    swap(a, b);
    b = 1;
    //cout << " | " << a << " " << b << " (" << a << " + sqrt(" << ro << ")) ";
    while(n){
        //cout << "(" << n << ", " << r << ", " << s << ", " << a << ", " << b << ") ";
        if(n & 1){
            i1 = (a * r + (b * s % P) * ro) % P;
            i2 = (a * s + b * r) % P;
            r = i1;
            s = i2;
        }
        i1 = (a * a + (b * b % P) * ro) % P;
        i2 = (2 * a * b) % P;
        a = i1;
        b = i2;
        n /= 2;
    }
    //cout << r << " " << s << " | ";
    return r;
}

int main(){
    scanf("%lld%lld%lld", &P, &R, &Q);
    it = mdp(2, P - 2);
    for(int Qi = 0; Qi < Q; ++Qi){
        scanf("%lld%lld%lld", &A, &B, &C);
        B = B * mdp(A, P - 2) % P;
        C = C * mdp(A, P - 2) % P;
        A = 1;
        //cout << "X^2 + " << B << " X + " << C << " = 0 (mod " << P << ") ";
        D = (B * B + 4 * (P - 1) * C) % P;
        //cout << D << " ";
        if(mdp(D, (P - 1) / 2) == P - 1){puts("-1");continue;}
        if(D == 0){
            x = 0;
            y = (((x + (P - 1) * B) % P) * it) % P;
            cout << y << endl;
        }else{
            int i;
            for(i = 0; i < P; ++i)if(mdp((i * i + (P - 1) * D) % P, (P - 1) / 2) == P - 1){y = (i * i + (P - 1) * D) % P;break;}
            x = pmdp(y, i);
            //cout << x << " ";
            y = (((x + (P - 1) * B) % P) * it) % P;
            x = (((P - 1) * (x + B) % P) * it) % P;
            cout << min(x, y) << " " << max(x, y) << endl;
        }
    }
    return 0;
}
0