結果

問題 No.1728 [Cherry 3rd Tune] Bullet
ユーザー SSRSSSRS
提出日時 2021-10-29 22:09:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 167,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 15:00:06
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
long long dfs(int C, vector<pair<int, int>> &G, int g, int cnt, int p){
  if (p == G.size()){
    return modpow(C, g * 2) * cnt % MOD;
  } else {
    int f = G[p].first;
    int c = G[p].second;
    long long ans = 0;
    for (int i = 0; i <= c; i++){
      if (i < c){
        ans += dfs(C, G, g, cnt / f * (f - 1), p + 1);
        g *= f;
        cnt /= f;
      } else {
        ans += dfs(C, G, g, cnt, p + 1);
      }
    }
    ans %= MOD;
    return ans;
  }
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N, C;
    cin >> N >> C;
    int N2 = N;
    vector<pair<int, int>> F;
    for (int j = 2; j * j <= N2; j++){
      if (N2 % j == 0){
        int cnt = 0;
        while (N2 % j == 0){
          N2 /= j;
          cnt++;
        }
        F.push_back(make_pair(j, cnt));
      }
    }
    if (N2 > 1){
      F.push_back(make_pair(N2, 1));
    }
    long long sum = dfs(C, F, 1, N, 0);
    sum += modpow(C, N) * N % MOD;
    long long ans = sum * modinv(N * 2) % MOD;
    cout << ans << endl;
  }
}
0