結果

問題 No.890 移調の限られた旋法
ユーザー CinnamorollCinnamoroll
提出日時 2019-09-20 22:39:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 7,345 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 177,872 KB
実行使用メモリ 10,844 KB
最終ジャッジ日時 2023-10-12 20:18:56
合計ジャッジ時間 9,336 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 393 ms
10,792 KB
testcase_14 AC 392 ms
10,828 KB
testcase_15 AC 390 ms
10,752 KB
testcase_16 AC 391 ms
10,732 KB
testcase_17 AC 338 ms
9,976 KB
testcase_18 AC 338 ms
9,992 KB
testcase_19 AC 160 ms
7,240 KB
testcase_20 AC 89 ms
5,624 KB
testcase_21 AC 12 ms
4,352 KB
testcase_22 AC 272 ms
8,984 KB
testcase_23 AC 359 ms
10,536 KB
testcase_24 AC 167 ms
7,196 KB
testcase_25 AC 24 ms
4,352 KB
testcase_26 AC 369 ms
10,564 KB
testcase_27 AC 381 ms
10,844 KB
testcase_28 AC 206 ms
7,984 KB
testcase_29 AC 115 ms
6,152 KB
testcase_30 AC 339 ms
9,888 KB
testcase_31 AC 157 ms
6,872 KB
testcase_32 AC 304 ms
9,452 KB
testcase_33 AC 330 ms
10,044 KB
testcase_34 AC 330 ms
10,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

  u64 a;

public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr bool operator==(const modint rhs) const noexcept {
    return modint(*this).val() == rhs.val();
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint = modint<MOD>;
typedef vector<mint> vec;
typedef vector<vector<mint>> mat;

int m;
vec matmul(vec &dp, mat &mt){
  vec ret(m,0);
  REP(i,m) REP(j,m) ret[i] += mt[i][j]*dp[j];
  return ret;
}

mat update(mat &mt){
  mat ret(m,vec(m,0));
  REP(i,m) REP(j,m) REP(k,m) ret[i][j] += mt[i][k]*mt[k][j];
  return ret;
}

void matpow(vec &dp, mat &mt, int k){
  m = dp.size();
  while(k){
    if(k%2) dp = matmul(dp,mt);
    mt = update(mt);
    k /= 2;
  }
}

vector<int> divisor(const int n){
  vector<int> ret;
  for(int i=1;i*i<=n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(i*i!= n) ret.push_back(n/i);
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n,k;
  cin >> n >> k;

  int g = __gcd(n,k);

  vector<int> list;
  for(int i=2;i<=n;i+=2){
    bool flag = true;
      for(int j=3; j<=sqrt(i);j+=2){
        if(i%j == 0){
        flag = false;
        break;
      }
    }
    if(flag || i == 2){
      int cnt = 0;
      while(g%i==0) g /= i, cnt++;
      if(cnt) g *= i,list.push_back(i);
    }
    if(i == 2) i--;
  }

  vector<int> a = divisor(g);

  vec fact(n+1,1);
  REP(i,n) fact[i+1] = fact[i]*(i+1);

  mint ans = 0;
  FOR(i,1,a.size()){
    int cnt = 0;
    REP(j,list.size()) if(a[i]%list[j]==0) cnt++;
    if(cnt%2) ans += fact[n/a[i]]/fact[n/a[i]-k/a[i]]/fact[k/a[i]];
    else ans -= fact[n/a[i]]/fact[n/a[i]-k/a[i]]/fact[k/a[i]];
  }

  cout << ans.val() << endl;

  return 0;
}
0