結果

問題 No.2324 Two Countries within UEC
ユーザー Haa
提出日時 2023-05-28 13:56:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 2,475 ms
コンパイル使用メモリ 167,484 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 22:19:59
合計ジャッジ時間 8,693 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;
ll extgcd(ll a, ll b, ll &x, ll &y) {
if(b==0){
x=1;
y=0;
return a;
}
ll gcd=extgcd(b,a%b,x,y);
ll oldX=x;
x=y;
y=oldX-a/b*y;
return gcd;
}
P crt2(ll b1, ll m1, ll b2, ll m2){
ll x, y;
ll d=extgcd(m1,m2,x,y);
if((b2-b1)%d!=0)
return {0,-1};
else{
ll m=m1*(m2/d);
return {((b1+((b2-b1)/d)*x%(m2/d)*m1)%m+m)%m,m};
}
}
int main(){
ll n, m, p, q;
cin >> n >> m >> p >> q;
ll x, f;
REP(i,q){
cin >> x >> f;
P r=crt2(f,p,0,x);
if(r.second==-1||r.first/x>m)
cout << 0 << endl;
else{
ll k=m-r.first/x;
cout << k/p+(r.first!=0) << endl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0