結果

問題 No.434 占い
ユーザー parukiparuki
提出日時 2016-10-19 18:31:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,897 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 179,304 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-02 05:43:57
合計ジャッジ時間 5,724 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 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 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 63 ms
5,376 KB
testcase_09 AC 17 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 62 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

string nstr(){
    static const int MAX_LEN = 1000000;
    static char res_[MAX_LEN];
    scanf("%s",res_);
    return string(res_);
}

template<class Val>
map<Val, int> factorize(Val n){
    map<Val, int> res;
    for(Val i=2; (long long)i*i<=n; ++i){
        while(n%i==0){
            n /= i;
            ++res[i];
        }
    }
    if(n!=1) ++res[n];
    return res;
}

int powMod(int n, int k, int mod){
    if(n==0)return 0;
    ll res = 1 % mod, nn = n;
    while(k){
        if(k&1)res=res*nn%mod;
        nn=nn*nn%mod;
        k>>=1;
    }
    return (int)res;
}

string S;


void solve() {

    int N = sz(S), ans = 0;
    if(count(all(S), '0') == N) {
        puts("0");
        return;
    }
    map<int, int> c;
    rep(i, N) {
        if(i != 0) {
            map<int, int> a = factorize<>(N - i), b = factorize<>(i);
            each(p, a)c[p.first] += p.second;
            vi r;
            each(p, b) {
                c[p.first] -= p.second;
                if(c[p.first] == 0) {
                    r.push_back(p.first);
                }
            }
            each(x, r)c.erase(x);
        }
        int x = 1;
        each(p, c)(x *= powMod(p.first, p.second, 9))%=9;
        (ans += x * (S[i]-'0')) %= 9;
    }
    if(ans == 0)ans = 9;
    printf("%d\n", ans);
}

int main(){
    int T; cin >> T;
    while(T--) {
        S = nstr();
        solve();
    }
}
0