結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー 👑 KazunKazun
提出日時 2021-08-15 19:06:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,452 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 90,308 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 13:33:49
合計ジャッジ時間 2,102 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 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 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 101 ms
5,376 KB
testcase_24 AC 64 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>

using namespace std;
using ll=long long;

vector<int> Divisors(int N){
    vector<int> D;
    int k=1;
    while (k*k<=N){
        if (N%k==0){
            D.push_back(k);
            if (k*k!=N){
                D.push_back(N/k);
            }
        }
        k++;
    }

    sort(D.begin(),D.end(),greater<int>());
    return D;
}

ll pow_mod(ll a, ll p, ll m){
    ll x=1;
    while (p){
        if (p&1){
            x*=a;
            x%=m;
        }
        a*=a; a%=m;
        p>>=1;
    }
    return x;
}

int main(){
    int T=0; cin >> T;

    ll mod=1000000007;
    int N,C;
    vector<int> D;
    int M,d,e,m,g;
    ll A,B,X;
    unordered_map<int, ll> H;
    for (int t=0; t<T; t++){
        cin >> N >> C;

        //gcd(N,x) の分布を調べる.
        D=Divisors(N);
        M=D.size();
        H.clear();

        for (int i=0; i<M; i++){
            d=D[i];
            H[d]=N/d;

            for (int j=0; j<i; j++){
                e=D[j];
                if (e%d==0) H[d]-=H[e];
            }
        }

        // σ^k 型の計算
        A=0;
        for (int i=0; i<M; i++){
            g=D[i]; m=2*g;
            A+=H[g]*pow_mod(C,m,mod);
            A%=mod;
        }

        // τ σ^k 型の計算
        B=N*pow_mod(C,N,mod);
        B%=mod;

        X=(A+B)*pow_mod(2*N,mod-2,mod);
        X%=mod;

        cout << X << endl;
    }
}
0