結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー 👑 tatyamtatyam
提出日時 2021-10-16 20:16:55
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 3,878 ms
コンパイル使用メモリ 284,804 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 13:48:46
合計ジャッジ時間 4,843 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using Modint = atcoder::modint1000000007;

vector<pair<int, int>> factor(int x){
    vector<pair<int, int>> ans;
    if(x % 2 == 0){
        ans.emplace_back(2, 1);
        while((x /= 2) % 2 == 0) ans.back().second++;
    }
    for(int y = 3; y * y <= x; y += 2) if(x % y == 0){
        ans.emplace_back(y, 1);
        while((x /= y) % y == 0) ans.back().second++;
    }
    if(x != 1) ans.emplace_back(x, 1);
    return ans;
}
void solve(){
    int N, c;
    cin >> N >> c;
    const Modint C = c;
    vector<pair<int, int>> a = {{1, 2}}; // (いくつあるか, 何乗するか)
    for(auto [p, q] : factor(N)){
        vector<pair<int, int>> b;
        vector<int> pow(q + 1);
        pow[0] = 1;
        for(int i = 0; i < q; i++) pow[i + 1] = pow[i] * p;
        for(int i = 0; i < q; i++) for(auto [x, y] : a) b.emplace_back(x * (pow.rbegin()[i] - pow.rbegin()[i + 1]), y * pow[i]);
        for(auto [x, y] : a) b.emplace_back(x, y * pow[q]);
        swap(a, b);
    }
    Modint ans = C.pow(N) * N;
    for(auto [x, y] : a) ans += C.pow(y) * x;
    cout << (ans / N / 2).val() << endl;
}
int main(){
    int T;
    cin >> T;
    while(T--) solve();
}
0