結果

問題 No.890 移調の限られた旋法
ユーザー butsurizukibutsurizuki
提出日時 2021-12-20 16:52:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 2,928 ms
コンパイル使用メモリ 255,296 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2023-10-13 19:32:53
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
19,808 KB
testcase_01 AC 16 ms
19,744 KB
testcase_02 AC 16 ms
19,736 KB
testcase_03 AC 17 ms
19,680 KB
testcase_04 AC 17 ms
19,756 KB
testcase_05 AC 16 ms
19,784 KB
testcase_06 AC 17 ms
19,800 KB
testcase_07 AC 17 ms
19,740 KB
testcase_08 AC 17 ms
19,784 KB
testcase_09 AC 17 ms
19,712 KB
testcase_10 AC 17 ms
19,712 KB
testcase_11 AC 16 ms
19,792 KB
testcase_12 AC 17 ms
19,736 KB
testcase_13 AC 17 ms
19,760 KB
testcase_14 AC 17 ms
19,716 KB
testcase_15 AC 17 ms
19,740 KB
testcase_16 AC 17 ms
19,684 KB
testcase_17 AC 17 ms
19,920 KB
testcase_18 AC 17 ms
19,688 KB
testcase_19 AC 17 ms
19,952 KB
testcase_20 AC 16 ms
19,776 KB
testcase_21 AC 17 ms
19,732 KB
testcase_22 AC 17 ms
19,684 KB
testcase_23 AC 17 ms
19,680 KB
testcase_24 AC 17 ms
19,860 KB
testcase_25 AC 17 ms
19,732 KB
testcase_26 AC 17 ms
19,728 KB
testcase_27 AC 17 ms
19,968 KB
testcase_28 AC 17 ms
19,704 KB
testcase_29 AC 16 ms
19,668 KB
testcase_30 AC 17 ms
19,688 KB
testcase_31 AC 16 ms
19,812 KB
testcase_32 AC 17 ms
19,768 KB
testcase_33 AC 16 ms
19,688 KB
testcase_34 AC 16 ms
19,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define mod 1000000007

using namespace std;

long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[1048576];
long long invfact[1048576];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<1048576;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[1048575]=modular_inverse(factorial[1048575]);
  for(i=1048574;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

int main(){
  cfact();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;
  map<int,long long> mp;
  vector<int> mem;
  for(int i=1;i*i<=n;i++){
    if(n%i){continue;}
    mem.push_back(i);
    if(i*i!=n){mem.push_back(n/i);}
  }
  sort(mem.begin(),mem.end());
  mem.pop_back();
  long long res=0;
  for(auto &nx : mem){
    int num=n/nx;
    if(k%num){continue;}
    int sing=k/num;
    long long cur=calcnCr(nx,sing);
    for(auto &ny : mp){
      if(nx%ny.first==0){
        cur+=(mod-ny.second);cur%=mod;
      }
    }
    mp[nx]=cur;
    res+=cur;res%=mod;
  }
  cout << res << '\n';
  return 0;
}
0