結果
問題 | No.1966 Median of Divisors |
ユーザー |
👑 ![]() |
提出日時 | 2022-06-03 22:34:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 416 ms / 2,000 ms |
コード長 | 1,049 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 169,944 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 03:01:06 |
合計ジャッジ時間 | 5,017 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define repr(i, n) for (int i = (int)(n); i >= 0; i--)#define all(v) v.begin(), v.end()#define mod1 1000000007#define mod2 998244353typedef long long ll;ll my_pow(ll x, ll n, ll mod){// 繰り返し二乗法.x^nをmodで割った余り.ll ret;if (n == 0){ret = 1;}else if (n % 2 == 1){ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;}else{ret = my_pow((x * x) % mod, n / 2, mod);}return ret;}int main(){ll T;cin >> T;for (ll z = 0; z < T; z++){ll N, M;cin >> N >> M;ll x = my_pow(N, M, mod1);ll y = my_pow(N, M / 2, mod1);ll s1 = (x * (x + 1)) % mod1;s1 = (s1 * my_pow(2LL, mod1 - 2, mod1)) % mod1;ll s2 = (y * (y + 1)) % mod1;s2 = (s2 * (2 * y + 1)) % mod1;s2 = (s2 * my_pow(6LL, mod1 - 2, mod1)) % mod1;cout << (s1 - s2 + mod1) % mod1 << endl;}}