結果
| 問題 |
No.3179 3 time mod
|
| コンテスト | |
| ユーザー |
tsunamayo123
|
| 提出日時 | 2025-05-30 22:41:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,313 bytes |
| コンパイル時間 | 8,171 ms |
| コンパイル使用メモリ | 446,296 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-05-30 22:41:24 |
| 合計ジャッジ時間 | 9,631 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 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;
ll L=(P*Q),D=P*x1+A;
D%=P*Q;
ll x22,y2;
extGCD(L,R,x22,y2);
mp::cpp_int x2=x22;
x2*=C-D;
mp::cpp_int n=L*x2+D;
n%=L*R;
if(n%prod<=N%prod){
cout<<ans+1<<endl;
}else{
cout<<ans<<endl;
}
}
tsunamayo123