結果

問題 No.890 移調の限られた旋法
ユーザー butsurizukibutsurizuki
提出日時 2021-12-20 16:51:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 5,448 ms
コンパイル使用メモリ 255,480 KB
実行使用メモリ 20,108 KB
最終ジャッジ日時 2023-10-13 19:32:47
合計ジャッジ時間 8,344 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
19,768 KB
testcase_01 AC 16 ms
20,044 KB
testcase_02 AC 16 ms
19,780 KB
testcase_03 AC 15 ms
19,768 KB
testcase_04 AC 16 ms
19,868 KB
testcase_05 AC 16 ms
20,040 KB
testcase_06 AC 17 ms
19,908 KB
testcase_07 AC 17 ms
19,912 KB
testcase_08 AC 17 ms
19,820 KB
testcase_09 AC 16 ms
19,808 KB
testcase_10 AC 16 ms
20,036 KB
testcase_11 AC 16 ms
19,984 KB
testcase_12 AC 16 ms
19,808 KB
testcase_13 AC 16 ms
19,784 KB
testcase_14 AC 16 ms
19,740 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 16 ms
19,768 KB
testcase_21 AC 16 ms
19,804 KB
testcase_22 WA -
testcase_23 AC 16 ms
19,812 KB
testcase_24 WA -
testcase_25 AC 16 ms
19,776 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 16 ms
19,764 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 17 ms
19,844 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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;
  }
  cout << res << '\n';
  return 0;
}
0