結果

問題 No.435 占い(Extra)
ユーザー latte0119
提出日時 2016-10-15 01:19:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,570 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 159,124 KB
実行使用メモリ 237,956 KB
最終ジャッジ日時 2024-10-08 11:57:36
合計ジャッジ時間 12,400 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 4
other MLE * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     scanf("%lld%lld%lld%lld%lld",&N,&x,&a,&b,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:68:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |     scanf("%lld",&T);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int SIZE=10000000;
int fact[SIZE],cnt[SIZE];
int inv[9];
int A[SIZE];
void solve(){
    int N,x,a,b,m;
    scanf("%lld%lld%lld%lld%lld",&N,&x,&a,&b,&m);
    A[0]=x;
    for(int i=1;i<N;i++){
        A[i]=((A[i-1]^a)+b)%m;
    }
    for(int i=0;i<N;i++)A[i]%=10;

    if(count(A,A+N,0)==N){
        puts("0");
        return;
    }

    N--;
    int ans=0;
    for(int i=0;i<=N;i++){
        int t=cnt[N]-cnt[i]-cnt[N-i];
        int f=fact[N]*inv[fact[i]]*inv[fact[N-i]]%9;
        if(t>=2)f=0;
        else if(t==1)f=f*3%9;
        ans=(ans+f*A[i])%9;
    }
    if(ans==0)ans=9;
    cout<<ans<<endl;
}

signed main(){

    fact[0]=1;
    cnt[0]=0;
    for(int i=1;i<SIZE;i++){
        int t=i;
        while(t%3==0){
            t/=3;
            cnt[i]++;
        }
        cnt[i]+=cnt[i-1];
        fact[i]=fact[i-1]*t%9;
    }
    for(int i=0;i<9;i++){
        if(i%3==0)continue;
        for(int j=0;j<9;j++)if(i*j%9==1)inv[i]=j;
    }

    int T;
    scanf("%lld",&T);
    while(T--)solve();
    return 0;
}
0