結果

問題 No.435 占い(Extra)
ユーザー fumofumofunifumofumofuni
提出日時 2021-10-19 22:10:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,807 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 205,476 KB
実行使用メモリ 51,956 KB
最終ジャッジ日時 2023-10-20 10:52:04
合計ジャッジ時間 9,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=2e9+1;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
vector<char> inv={0,1,5,0,7,2,0,4,8};
int maxN=1e7+10;
vector<char> a(maxN);
vector<int> b(maxN);
void precalc(){
  a[0]=1;b[0]=0;
  for(int i=1;i<maxN;i++){
    if(i%3==0){
      a[i]=a[i/3];
      b[i]=b[i/3]+1;
    }
    else a[i]=i%9;
  }
  for(int i=1;i<maxN;i++){
    a[i]=(a[i-1]*a[i])%9;
    b[i]+=b[i-1];
  }
}
ll comb(ll n,ll k){
  ll bs=b[n]-b[k]-b[n-k];
  if(bs>=2)return 0;
  if(bs)bs=3;
  else bs=1;
  bs=bs*a[n]*inv[a[n-k]]*inv[a[k]]%9;
  return bs;
}
int main(){
  precalc();
  ll t;cin >> t;
  /*for(int i=maxN-20;i<maxN;i++){
    cout << b[i] << endl;
  }*/
  int n,x,a,b,m;
  while(t--){
    cin >> n >> x >> a >> b >> m;
    int ans=0;
    bool zero=true;
    rep(i,n){
      if(x%10)zero=false;
      ans+=(x%10)*comb(n-1,i)%9;
      x=((x^a)+b)%m;
    }
    ans%=9;
    if((!zero)&&(!ans))ans+=9;
    cout << ans << endl;
  }
}  
0