結果

問題 No.551 夏休みの思い出(2)
ユーザー 小指が強い人小指が強い人
提出日時 2017-08-20 01:56:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,643 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 181,768 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-22 17:22:08
合計ジャッジ時間 8,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,960 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < (ll)n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T, class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<char c = ' ',class T> void write(T a){cout << fixed << setprecision(12) << a << endl;}
template<char c = ' ',class T,class ...Args> void write(T a, Args... args){cout << fixed << setprecision(4) << a << c; write<c>(args...);}
template<class T> void warr(T a, const char* c = " "){cout << a;for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ull gcd(ull a, ull b){while(true){ull k = a % b;if(k == 0)return b;a = b;b = k;}}
ull comb(ull n, ull m){ull p=1;m=min(m,n-m);for(ull i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

ull power( const ull& a, ull k, const ull& n )
{
  if ( a == 0 || n == 0 ) return( 0 );
  if ( k == 0 ) return( 1 % n );

  ull currentMod = a % n;
  ull currentValue = ( ( k & 1 ) > 0 ) ? currentMod : 1;

  for ( k >>= 1 ; k > 0 ; k >>= 1 ) {
    currentMod = ( currentMod * currentMod ) % n;
    if ( ( k & 1 ) > 0 )
      currentValue = ( currentValue * currentMod ) % n;
  }

  return( currentValue );
}

int main(void)
{
    ll p,r,q;
    map<int,int> mp;
    read(p,r,q);
    ll m=ceil(sqrt(p));
    rep(i,m){
        int yy=power(r,i,p);
        mp[yy]=i;
    }
    //int i2=power(2,p-2,p);
    //int d2p=(p-1)/2;
    ll irm=power(power(r,p-2,p),m,p);
    rep(i,q){
        ll a,b,c;
        read(a,b,c);
        if(b==0&&c==0){
            write(0);
            continue;
        }
        ll d=(b*b-4*a*c)%p;
        if(d==0){
            write(((-b+p)*power(2*a,p-2,p))%p);
            continue;
        }
        if(d<0)d=(d+p)%p;
        ll v=d;
        set<int> res;
        rep(j,m){
            if(mp.count(v)){
                ll x=j*m+mp[v];
                //write(i,x);
                if(x%2==0){
                    ll gx=power(r,x/2,p);
                    ll x1=(gx-b+p)*power(2*a,p-2,p);
                    res.insert(x1%p);
                    //res.insert((x1+d2p)%p);
                }
            }
            v=(v*irm)%p;
        }
        //continue;
        if(res.size()>0){
            bool init=false;
            for(auto a:res){
                if(init)cout<<" ";
                cout<<a;
                init=true;
            }
            cout<<endl;
        }
        else write(-1);
    }
    return 0;
}
0