結果

問題 No.1973 Divisor Sequence
ユーザー renren_utsrenren_uts
提出日時 2022-06-16 07:04:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,388 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 136,772 KB
実行使用メモリ 393,580 KB
最終ジャッジ日時 2024-04-15 17:18:08
合計ジャッジ時間 10,178 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
13,880 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 153 ms
6,944 KB
testcase_03 AC 153 ms
6,940 KB
testcase_04 AC 151 ms
6,944 KB
testcase_05 AC 155 ms
6,944 KB
testcase_06 AC 155 ms
6,944 KB
testcase_07 AC 156 ms
6,944 KB
testcase_08 AC 154 ms
6,944 KB
testcase_09 AC 154 ms
6,940 KB
testcase_10 AC 153 ms
6,944 KB
testcase_11 AC 150 ms
6,944 KB
testcase_12 AC 153 ms
6,940 KB
testcase_13 AC 156 ms
6,944 KB
testcase_14 AC 719 ms
6,940 KB
testcase_15 AC 154 ms
6,944 KB
testcase_16 AC 153 ms
6,940 KB
testcase_17 AC 151 ms
6,940 KB
testcase_18 AC 159 ms
6,940 KB
testcase_19 AC 151 ms
6,944 KB
testcase_20 AC 153 ms
6,940 KB
testcase_21 AC 151 ms
6,940 KB
testcase_22 AC 155 ms
6,944 KB
testcase_23 AC 153 ms
6,944 KB
testcase_24 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <tuple>
#include <bitset>
#include <map>
#include <queue>
#include <time.h>
#include <utility>
#include <numeric>
#include <deque>
#include <cassert>
#include <sstream>
#include <cctype>
#include <unordered_map>
#include <algorithm>
#include <chrono>
#define ll long long
#include <time.h>
#define mod % 1000000007
#define rep(i,n) for(long long i = 0;i < n;i ++)
ll MAX = 5'000'000'000'000'000'000LL;
using namespace std;

 vector<ll> p;

void MAKE_P(){
  p = {2,3};
  for(int i = 5;i <= 1000000;i ++){
    bool z = true;
    for(ll j:p){
      if(i%j==0){
        z = false;
        break;
      }
      if(j*j>i)break;
    }
    if(z)p.push_back(i);
  }
}

vector<vector<ll>> sub(vector<ll> q){
  vector<vector<ll>> Q;
  ll z = q.size();
  if(z==1){
    rep(i,q[0]+1){
      Q.push_back({i});
    }
    return Q;
  }
  vector<ll> r = q;
  r.pop_back();
  vector<vector<ll>> R = sub(r);
  for(auto a:R){
    rep(i,q[z-1]+1){
      a.push_back(i);
      Q.push_back(a);
      a.pop_back();
    }
  }
  return Q;
}

vector<ll> mul(vector<vector<ll>> A,vector<ll> B,ll n){
  vector<ll> C(n,0);
  rep(i,n){
    rep(j,n){
      C[j] += (A[i][j]*B[i]) mod;
    }
  }
  rep(i,n)C[i] = C[i] mod;
  return C;
}

vector<vector<ll>> mult(vector<vector<ll>> A,ll n){
  vector<vector<ll>> B(n,vector<ll>(n,0));
  rep(i,n){
    rep(j,n){
      rep(k,n){
        B[i][j] += (A[i][k]*A[k][j]) mod;
      }
    }
  }
  rep(i,n){
    rep(j,n){
      B[i][j] = B[i][j] mod;
    }
  }
  return B;
}

int main(){
  ll n,m;
  cin >> n >> m;
  if(m==1){
    cout << 1 << endl;
    return 0;
  }
  MAKE_P();
  vector<ll> q;
  rep(i,int(p.size())){
    if(m%p[i]==0){
      q.push_back(0);
      while(m%p[i] == 0){
        q[int(q.size())-1] ++;
        m = m/p[i];
      }
    }
  }
  if(m>1)q.push_back(1);
  vector<vector<ll>> Q = sub(q);
  map<vector<ll>,ll> mp;
  ll x = Q.size();
  rep(i,x){
    mp[Q[i]] = i;
  }
  vector<vector<ll>> A(x,vector<ll>(x,0));
  rep(i,x){
    auto w = q;
    rep(j,int(q.size())){
      w[j] -= Q[i][j];
    }
    auto a = sub(w);
    for(auto b:a){
      A[i][mp[b]] ++;
    }
  }
  vector<ll> B(x,0);
  B[0] = 1;
  while(n > 0){
    if(n%2==1){
      B = mul(A,B,x);
    }
    A = mult(A,x);
    n = n/2;
  }
  ll ans = 0;
  rep(i,x)ans += B[i];
  cout << ans mod << endl;
  
  return 0;
}
0