結果

問題 No.435 占い(Extra)
ユーザー 🐬hec🐬hec
提出日時 2016-05-05 19:32:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,748 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 165,128 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-17 02:26:31
合計ジャッジ時間 12,280 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,704 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 96 ms
5,376 KB
testcase_11 AC 59 ms
5,376 KB
testcase_12 AC 1,740 ms
5,376 KB
testcase_13 AC 884 ms
5,376 KB
testcase_14 AC 562 ms
5,376 KB
testcase_15 AC 378 ms
5,376 KB
testcase_16 AC 157 ms
5,376 KB
testcase_17 AC 166 ms
5,376 KB
testcase_18 AC 1,689 ms
5,376 KB
testcase_19 AC 896 ms
5,376 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

using namespace std;

const int limit=10000000;

vector<int> calc(int n){
    vector<int> ret(10,0);
    for(int i=2;i*i<=n;++i) while(n%i==0) ret[i%9]++,n/=i;
    if(n!=1) ret[n%9]++;
    return ret;
}

int power(int a,int n,int mod){
    int b=1;
    while(n){
        if(n&1) b=b*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return b;
}

const int t_limit=10000000;
const int n_limit=10000000;

int main(void){
    int t=0,all=0;
    scanf("%d",&t);
    assert(1<=t&&t<=t_limit);

    rep(loop,t){
        int n,x,a,b,m;
        scanf("%d %d %d %d %d",&n,&x,&a,&b,&m);
        assert(1<=n && n<=n_limit);
        assert(0<=x && x<=1e9);
        assert(0<=a && a<=1e9);
        assert(0<=b && b<=1e9);
        assert(1<=m && m<=1e9);
        all+=n;
        
        bool allzero=true;
        int ans=0,f[10];
        fill(f,f+10,0);
        int num=n-1,den=1;
        rep(i,n){
            int cur=x%10;
            x=((x^a)+b)%m;
            if(cur!=0) allzero=false;
            rep(j,10) cur=(cur*power(j,f[j],9))%9;
            ans=(ans+cur)%9;
            vector<int> factor_num=calc(num),factor_den=calc(den);
            rep(j,10) f[j]+=factor_num[j];
            rep(j,10) f[j]-=factor_den[j];
            num--,den++;
        }

        if(allzero==false && ans==0) ans=9;
        printf("%d\n",ans);
    }
    assert(all<=n_limit);
    return 0;
}
0