結果
| 問題 |
No.1728 [Cherry 3rd Tune] Bullet
|
| コンテスト | |
| ユーザー |
👑 tatyam
|
| 提出日時 | 2021-10-16 20:16:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,231 bytes |
| コンパイル時間 | 3,714 ms |
| コンパイル使用メモリ | 256,596 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-07 09:16:26 |
| 合計ジャッジ時間 | 4,070 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#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();
}
tatyam