結果

問題 No.1581 Multiple Sequence
ユーザー rnanornano
提出日時 2023-09-09 01:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 3,411 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 204,580 KB
実行使用メモリ 26,164 KB
最終ジャッジ日時 2023-09-09 01:10:59
合計ジャッジ時間 6,347 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 199 ms
22,264 KB
testcase_03 AC 242 ms
23,868 KB
testcase_04 AC 51 ms
10,544 KB
testcase_05 AC 229 ms
24,628 KB
testcase_06 AC 93 ms
14,304 KB
testcase_07 AC 57 ms
10,264 KB
testcase_08 AC 68 ms
12,240 KB
testcase_09 AC 203 ms
23,036 KB
testcase_10 AC 126 ms
17,148 KB
testcase_11 AC 24 ms
7,480 KB
testcase_12 AC 76 ms
12,980 KB
testcase_13 AC 4 ms
4,636 KB
testcase_14 AC 240 ms
24,164 KB
testcase_15 AC 150 ms
19,076 KB
testcase_16 AC 30 ms
8,204 KB
testcase_17 AC 245 ms
25,792 KB
testcase_18 AC 20 ms
6,916 KB
testcase_19 AC 188 ms
21,696 KB
testcase_20 AC 198 ms
22,632 KB
testcase_21 AC 239 ms
23,960 KB
testcase_22 AC 114 ms
16,296 KB
testcase_23 AC 257 ms
26,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,a,b) for (int i = a; i < b; ++i)
#define rRep(i,a,b) for (int i = a; i > b; --i)
#define fore(i,a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define Bit(x,i) (((x)>>(i))&1)
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T, size_t n, size_t idx = 0> auto mvec(const size_t (&d)[n], const T& init) noexcept { if constexpr (idx < n) return std::vector(d[idx], mvec<T, n, idx + 1>(d, init)); else return init; }
template<class T, size_t n> auto mvec(const size_t (&d)[n]) noexcept { return mvec(d, T{}); }
void print(){ cout << '\n'; }
template<class T, class... Ts> void print(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class... T> constexpr auto Min(T... a){ return min(initializer_list<common_type_t<T...>>{a...}); }
template<class... T> constexpr auto Max(T... a){ return max(initializer_list<common_type_t<T...>>{a...}); }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
struct settings{ settings(){ ios_base::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(15); }; }settingss;
const double PI = acos(-1);
const int INF = 1001001001;
const ll LINF = 1001001001001001001LL;

const int mod = 1000000007;
class modint {
  long long x;
public:
  modint(long long x=0) : x((x%mod+mod)%mod) {}
  modint operator-() const {
    return modint(-x);
  }
  modint& operator+=(const modint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator-=(const modint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator*=(const  modint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint operator+(const modint& a) const {
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint& a) const {
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint& a) const {
    modint res(*this);
    return res*=a;
  }
  modint pow(ll t) const {
    if (!t) return 1;
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  modint inv() const {
    return pow(mod-2);
  }
  modint& operator/=(const modint& a) {
    return (*this) *= a.inv();
  }
  modint operator/(const modint& a) const {
    modint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const modint& m){
    os << m.x;
    return os;
  }
};

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (ll i = 1; 1LL*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;
}

modint memo[100100];
bool used[100100];

modint calc(ll m) {
  if(m == 0) return 1;
  if(used[m]) return memo[m];
  vll D = divisor(m);
  modint ret = 0;
  fore(nx, D) {
    ret += calc(m/nx - 1);
  }
  used[m] = true;
  memo[m] = ret;
  return ret;
}

int main() {
  ll M; cin >> M;
  vll D = divisor(M);
  cout << calc(M) << endl;
}
0