結果

問題 No.3179 3 time mod
ユーザー tsunamayo123
提出日時 2025-05-30 21:22:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 2,837 ms
コンパイル使用メモリ 275,360 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-30 21:22:21
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

#ifdef LOCAL
#include <cpp-dump.hpp>
// #include "cpp-dump-modint.hpp"
#define debug(...) cpp_dump(__VA_ARGS__)
namespace cp = cpp_dump;
// CPP_DUMP_SET_OPTION_GLOBAL(log_label_func, cpp_dump::log_label::filename(true));
CPP_DUMP_SET_OPTION_GLOBAL(max_iteration_count, std::numeric_limits<std::size_t>::max());
#else
#define debug(...) (static_cast<void>(0))
#endif

int main(){
    // input
    ll N,P,Q,R,A,B,C;
    cin>>N>>P>>Q>>R>>A>>B>>C;

    // ans=0に注意
    ll prod=P*Q*R;
    ll ans=N/prod;

    ll x1,y1;
    // gcd(P,Q,R)=1より拡張ユーグリッドの互除法が使える
    extGCD(P,Q,x1,y1);
    x1*=B-A;

    ll L=lcm(P,Q),D=P*x1+A;

    ll x2,y2;
    extGCD(L,R,x2,y2);
    x2*=C-D;

    ll n=L*x2+D;
    
    if(n%prod<=N%prod){
        cout<<ans+1<<endl;
    }else{
        cout<<ans<<endl;
    }
}
0