結果

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

ソースコード

diff #

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

const int SIZE=10000000;
char A[SIZE];
char F[SIZE];
int inv[9];
inline int f(int x){
    int ret=0;
    while(x){
        ret+=x/3;
        x/=3;
    }
    return ret;
}

void solve(){
    int N,x,a,b,m;
    scanf("%d%d%d%d%d",&N,&x,&a,&b,&m);
    A[0]=x%10;
    for(int i=1;i<N;i++){
        x=((x^a)+b)%m;
        A[i]=x%10;
    }

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

    N--;
    int fn=f(N);


    int ans=0;
    for(int i=0;i<=N;i++){
        int tmp=fn-f(i)-f(N-i);
        int t=F[N]*inv[F[i]]*inv[F[N-i]]%9;
        if(tmp>=2)t=0;
        else if(tmp==1)t=t*3%9;
        ans=(ans+t*A[i])%9;
    }
    if(ans==0)ans=9;
    printf("%d\n",ans);
}

int main(){
    F[0]=1;
    for(int i=1;i<SIZE;i++){
        int t=i;
        while(t%3==0)t/=3;
        F[i]=F[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("%d",&T);
    while(T--)solve();
}
0