結果

問題 No.1671 Permutation Tour
ユーザー monnu
提出日時 2021-09-04 20:14:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 4,340 ms
コンパイル使用メモリ 228,416 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 13:59:49
合計ジャッジ時間 5,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

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