結果

問題 No.434 占い
ユーザー 🐬hec🐬hec
提出日時 2016-05-05 19:29:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 165,976 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 07:51:53
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 94 ms
6,940 KB
testcase_16 AC 59 ms
6,940 KB
testcase_17 AC 39 ms
6,940 KB
testcase_18 AC 17 ms
6,940 KB
testcase_19 AC 13 ms
6,944 KB
testcase_20 AC 23 ms
6,940 KB
testcase_21 AC 94 ms
6,944 KB
testcase_22 AC 58 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 53 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 35 ms
6,944 KB
testcase_27 AC 33 ms
6,940 KB
testcase_28 AC 30 ms
6,944 KB
testcase_29 AC 17 ms
6,940 KB
testcase_30 AC 21 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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=100000;

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=100000;
const int n_limit=100000;

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

    rep(loop,t){
        char s[limit+1];
        scanf("%s",s);
        int n=strlen(s);
        assert(1<=n);
        all+=n;
        

        bool allzero=true;
        rep(i,n) if(s[i]!='0') allzero=false;
        
        if(allzero){
            puts("0");
            continue;
        }

        int ans=0,f[10];
        fill(f,f+10,0);
        int num=n-1,den=1;
        rep(i,n){
            int cur=s[i]-'0';
            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(ans==0) ans=9;
        printf("%d\n",ans);
    }
    assert(all<=n_limit);
    return 0;
}
0