結果

問題 No.1966 Median of Divisors
ユーザー keisuke6keisuke6
提出日時 2022-06-03 23:12:55
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 3,289 ms
コンパイル使用メモリ 246,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 02:23:14
合計ジャッジ時間 6,031 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 248 ms
4,348 KB
testcase_05 AC 333 ms
4,348 KB
testcase_06 AC 312 ms
4,348 KB
testcase_07 AC 30 ms
4,348 KB
testcase_08 AC 175 ms
4,348 KB
testcase_09 AC 233 ms
4,348 KB
testcase_10 AC 232 ms
4,348 KB
testcase_11 AC 119 ms
4,348 KB
testcase_12 AC 159 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000000007;
int f(int x, int n, int m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return f(x * x % m, n / 2, m);
  else
    return x * f(x, n - 1, m) % m;
}
int g(int n,int m){
    return (n*(n+1)/2)%m;
}
int h(int n,int m){
    if((2*n+1)%3 == 0) return (((n*(n+1)/2)%m*(2*n+1))/3)%m;
    else return n*(n+1)/6%m*(2*n+1)%m;
}
signed main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
      int N,M;
      cin>>N>>M;
      cout<<(g(f(N,M,mod),mod)-h(f(N,M/2,mod),mod)+mod)%mod<<endl;
  }
}
0