結果

問題 No.3179 3 time mod
ユーザー Rumain831
提出日時 2025-06-13 22:05:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 75,908 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-13 22:06:00
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 3 WA * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

ll extgcd(ll a, ll b, ll& x, ll& y){
  if(b==0){
    x=1, y=0; return a;
  }
  ll x1, y1;
  ll gcd=extgcd(b, a%b, x1, y1);
  x=y1; y=x1-(a/b)*y1;
  return gcd;
}

int main(void){
  ll n; cin >> n;
  ll p, q, r, a, b, c; cin >> p >> q >> r >> a >> b >> c;
  ll x, y;
  ll pq=p*q, pqr=p*q*r;
  extgcd(p, q, x, y);
  //px+qy=1
  //px=1 mod q
  //qy=1 mod p
  ll s=p*b%pq*x%pq+a*q%pq*y%pq; s=(s+pq)%pq;
  //x=s mod pq
  //x=c mod r
  extgcd(p*q, r, x, y);
  
  ll t=(pq*c)%pqr*x%pqr+s*r%pqr*y%pqr; t=(t+pqr)%pqr;
  //cout << pqr << ' ' << t << endl;
  if(t>n){
    cout << 0 << endl; return 0;
  }
  ll left=1, right=2e18/pqr;
  while(right-left>1){
    ll mid=(left+right)/2;
    ll now=mid*pqr+t;
    if(now<=n) left=mid;
    else right=mid;
  }
  if(a*a+b*b+c*c==0) left++;
  cout << left << endl;
  return 0; 
}
0