結果

問題 No.2193 メガの下1桁
ユーザー hotman78hotman78
提出日時 2023-01-13 22:31:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,902 bytes
コンパイル時間 2,970 ms
コンパイル使用メモリ 223,676 KB
実行使用メモリ 14,040 KB
最終ジャッジ日時 2023-08-26 04:15:19
合計ジャッジ時間 5,376 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 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,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 56 ms
13,888 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 74 ms
14,040 KB
testcase_29 AC 71 ms
13,984 KB
testcase_30 AC 6 ms
4,380 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 292 ms
13,908 KB
testcase_34 AC 14 ms
4,380 KB
testcase_35 AC 34 ms
4,380 KB
testcase_36 WA -
testcase_37 RE -
testcase_38 WA -
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

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<(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;
            bool over=0;
            rep(j,v[i+1]){
                tmp*=v[i]+d;
                if(tmp>=phi[i]*2)tmp=tmp%phi[i]+phi[i];
            }
            res[i]=tmp;
        }
        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%phi[i]+(m>=phi[i]?phi[i]:0);
    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){
            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]=mul(t);
        }
        n/=2;
        swap(ma,ma2);
    }
    if(ans[0]%b==10)cout<<"A"<<endl;
    else cout<<ans[0]%b<<endl;
}
0