結果
問題 |
No.3179 3 time mod
|
ユーザー |
![]() |
提出日時 | 2025-05-30 21:31:35 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,332 bytes |
コンパイル時間 | 3,422 ms |
コンパイル使用メモリ | 273,728 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-30 21:32:08 |
合計ジャッジ時間 | 4,398 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 WA * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; // https://qiita.com/drken/items/b97ff231e43bce50199a // けんちょんさんの記事より // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } int main(){ // input ll N,P,Q,R,A,B,C; cin>>N>>P>>Q>>R>>A>>B>>C; // ans=0に注意 ll d[3]={P,Q,R}; ll r[3]={A,B,C}; for(int i=0;i<3;i++){ for(int j=i+1;j<3;j++){ if(d[i]==d[j]&&r[i]!=r[j]){ cout<<0<<endl; return 0; } } } ll prod=P*Q*R; ll ans=N/prod; ll x1,y1; extGCD(P,Q,x1,y1); // gcd(P,Q,R)=1より拡張ユーグリッドの互除法が使える x1*=B-A; if(x1<0){ x1=lcm(P,Q)*((lcm(P,Q)/(-x1))+1); } x1%=lcm(P,Q); ll L=lcm(P,Q),D=P*x1+A; ll x2,y2; extGCD(L,R,x2,y2); x2*=C-D; if(x2<0){ x2=lcm(L,R)*((lcm(L,R)/(-x2))+1); } x2%=lcm(L,R); ll n=L*x2+D; if(n%prod<=N%prod){ cout<<ans+1<<endl; }else{ cout<<ans<<endl; } }