結果

問題 No.1671 Permutation Tour
ユーザー monnumonnu
提出日時 2021-09-04 20:14:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 3,785 ms
コンパイル使用メモリ 226,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 11:28:05
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 60
#define MOD 1000000007
#define INF 1000000000000000000

ll modpow(ll a, ll n){
  ll ret=1;
  a%=MOD;
  while(n>0){
    if((n&1)==1){
      ret=ret*a%MOD;
    }
    n>>=1;
    a=a*a%MOD;
  }
  return ret;
}

ll modinv(ll x){
  return modpow(x,MOD-2);
}

int main(){
  ll N;
  cin>>N;
  ll ans=0;
  ans+=N*((N-1)*N/2%MOD)%MOD;
  ans%=MOD;
  ans+=MOD-(N*(N-1)%MOD)*((2*N-1)*modinv(6)%MOD)%MOD;;
  ans%=MOD;
  ans*=2*modinv(N-1);
  ans%=MOD;
  cout<<ans<<'\n';
}
0