結果

問題 No.2193 メガの下1桁
ユーザー hotman78hotman78
提出日時 2023-01-13 23:37:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 904 ms / 2,000 ms
コード長 2,049 bytes
コンパイル時間 2,590 ms
コンパイル使用メモリ 224,832 KB
実行使用メモリ 14,192 KB
最終ジャッジ日時 2023-08-26 05:12:56
合計ジャッジ時間 5,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 47 ms
14,032 KB
testcase_18 AC 104 ms
14,036 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 65 ms
14,192 KB
testcase_29 AC 64 ms
13,976 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 193 ms
13,908 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 26 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 29 ms
4,376 KB
testcase_38 AC 22 ms
4,380 KB
testcase_39 AC 904 ms
14,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/math.hpp>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<ll(n);++i)

vector<vector<long long>> make_mat(vector<long long> v){
    if(v.empty())return vector<vector<long long>>(1,vector<long long>());
    long long n=v.back();
    v.pop_back();
    vector<vector<long long>> ret;
    vector<vector<long long>> tmp=make_mat(v);
    for(auto e:tmp)for(long long i=0;i<n;++i){
        ret.push_back(e);
        ret.back().push_back(i);
    }
    return ret;
}

ll euler_phi(ll n) {
  ll ret = n;
  for(ll i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main(){
    ll m,d,n,b;
    cin>>m>>d>>n>>b;
    vector<ll>phi=vector{b};
    while(phi.back()!=1){
        phi.emplace_back(euler_phi(phi.back()));
    }
    auto mul=[&](vector<ll>v){
        vector<ll>res(phi.size());
        rep(i,phi.size()-1){
            ll tmp=1,k=v[i]+d;
            if(k>=phi[i]*2)k=k%phi[i]+phi[i];
            bool over=0;
            rep(j,v[i+1]){
                tmp*=k;
                if(tmp>=phi[i]*2)tmp=tmp%phi[i]+phi[i];
            }
            res[i]=tmp;
        }
        res.back()=1;
        return res;
    };
    auto tb=phi;
    rep(i,phi.size())tb[i]*=2;
    map<vector<ll>,vector<ll>>ma;
    for(auto v:make_mat(tb)){
        ma[v]=mul(v);
    }
    vector<ll>v(phi.size());
    rep(i,phi.size()){
        v[i]=m;
        if(v[i]>=phi[i]*2)v[i]=v[i]%phi[i]+phi[i];
    }
    auto ans=v;
    // cerr<<n<<endl;
    // rep(i,phi.size())cerr<<phi[i]<<ans[i]<<" \n"[i==phi.size()-1];
    while(n){
        if(n%2){
            assert(ma.count(ans));
            ans=ma[ans];
            // rep(i,phi.size())cerr<<phi[i]<<ans[i]<<" \n"[i==phi.size()-1];
        }
        map<vector<ll>,vector<ll>>ma2;
        for(auto [s,t]:ma){
            ma2[s]=ma[t];
        }
        n/=2;
        swap(ma,ma2);
    }
    if(ans[0]%b==10)cout<<"A"<<endl;
    else cout<<ans[0]%b<<endl;
}
0