結果
| 問題 | No.3179 3 time mod |
| コンテスト | |
| ユーザー |
tsunamayo123
|
| 提出日時 | 2025-05-30 22:59:46 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,373 bytes |
| 記録 | |
| コンパイル時間 | 752 ms |
| コンパイル使用メモリ | 92,836 KB |
| 最終ジャッジ日時 | 2026-01-17 06:31:34 |
| 合計ジャッジ時間 | 1,623 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:4:10: 致命的エラー: boost/multiprecision/cpp_int.hpp: そのようなファイルやディレクトリはありません
4 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
コンパイルを停止しました。
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
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;
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;
if(n<0){
n+=(L*R)*(((-n)/(L*R))+1);
}
n%=L*R;
if(n%prod<=N%prod){
cout<<ans+1<<endl;
}else{
cout<<ans<<endl;
}
}
tsunamayo123