結果

問題 No.551 夏休みの思い出(2)
ユーザー fumofumofuni
提出日時 2022-08-27 11:29:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,011 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 208,308 KB
最終ジャッジ日時 2025-01-31 06:21:00
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26 TLE * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll modlog(ll)’:
main.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
   63 | }
      | ^

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,1,0,-1,1,-1,1,-1,0};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
ll modpow(ll a,ll n, ll mod) {
a%=mod;if(a==0)return 0;
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll p,r;
ll safemod(ll x){
return (x%p+p)%p;
}
ll modlog(ll s){
unordered_map<ll,ll> mp;
ll f=1;
rep(i,32000){
mp[f]=i;
f=f*r%p;
}
ll dif=modpow(r,32000,p);
dif=modpow(dif,p-2,p);
f=s;
rep(i,32000){
if(mp.count(f)){
return (mp[f]+i*32000)%(p-1);
}
f=f*dif%p;
}
}
void solve(){
ll a,b,c;cin >> a >> b >> c;
ll s=safemod(b*b-4*a*c);
if(s==0){
cout << safemod(-b*modpow(a*2,p-2,p)) << endl;return;
}
ll k=modlog(s);
if(k&1){
cout << -1 << endl;
return ;
}
//cout << k << endl;
ll x=k/2,y=(k+p-1)/2;
x=modpow(r,x,p),y=modpow(r,y,p);
vl ans={x,-x,y,-y};
ll inva=modpow(a*2,p-2,p);
rep(i,4){
ans[i]=safemod((ans[i]-b)*inva);
}
sort(all(ans));ans.erase(unique(all(ans)),ans.end());
for(auto p:ans)cout << p << " ";cout << endl;
}
int main(){
cin >> p >> r;
ll t;cin >> t;
while(t--)solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0