結果

問題 No.2417 Div Count
ユーザー toshihogetoshihoge
提出日時 2023-08-12 13:42:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 11,516 bytes
コンパイル時間 3,573 ms
コンパイル使用メモリ 176,980 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-19 15:57:28
合計ジャッジ時間 4,556 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 AC 2 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 2 ms
5,248 KB
testcase_23 AC 2 ms
5,248 KB
testcase_24 AC 2 ms
5,248 KB
testcase_25 AC 2 ms
5,248 KB
testcase_26 AC 2 ms
5,248 KB
testcase_27 AC 2 ms
5,248 KB
testcase_28 AC 2 ms
5,248 KB
testcase_29 AC 3 ms
5,248 KB
testcase_30 AC 2 ms
5,248 KB
testcase_31 AC 2 ms
5,248 KB
testcase_32 AC 5 ms
5,248 KB
testcase_33 AC 4 ms
5,248 KB
testcase_34 AC 3 ms
5,248 KB
testcase_35 AC 7 ms
5,248 KB
testcase_36 AC 5 ms
5,248 KB
testcase_37 AC 5 ms
5,248 KB
testcase_38 AC 12 ms
5,248 KB
testcase_39 AC 6 ms
5,248 KB
testcase_40 AC 4 ms
5,248 KB
testcase_41 AC 3 ms
5,248 KB
testcase_42 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <atcoder/all>
#include <chrono>
#include <complex>
#include <functional>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<vi> vvi;

typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef vector<ull> vull;
typedef vector<vull> vvull;

typedef vector<string> vstring;

typedef complex<double> cd;
typedef complex<int> ci;
typedef complex<ll> cll;

string toYN(bool b) { return b ? "Yes" : "No"; }

// https://ei1333.github.io/luzhiled/snippets/other/random-number-generator.html
struct RandomNumberGenerator {
  mt19937 mt;

  RandomNumberGenerator()
      : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) {  // [a, b)
    uniform_int_distribution<int> dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) {  // [0, b)
    return (*this)(0, b);
  }
};

// loop macro
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

// read helper
template <typename T>
inline void read(int n, std::vector<T> &array) {
  array = std::vector<T>(n);
  REP(i, n) { cin >> array[i]; }
}

template <typename T>
inline void read(int n, int m, std::vector<std::vector<T>> &matrix) {
  matrix = std::vector<std::vector<T>>(n, std::vector<T>(m));
  REP(i, n) {
    REP(j, m) { cin >> matrix[i][j]; }
  }
}

// write helper
template <typename T>
inline void write(std::vector<T> array) {
  for (const T &t : array) {
    cout << t << endl;
  }
}

template <typename T>
inline void writeOneLine(std::vector<T> array) {
  bool first = true;
  for (const T &t : array) {
    if (!first) {
      cout << " ";
    }
    cout << t;
    first = false;
  }
  cout << endl;
}

// vector helper
// test by iterator_macro_test.cpp
template <typename T>
inline typename vector<T>::const_iterator moreThan(
    const std::vector<T> &sortedVector, const T &key) {
  return upper_bound(sortedVector.begin(), sortedVector.end(), key);
}
template <typename T>
inline typename vector<T>::const_iterator moreThanEq(
    const std::vector<T> &sortedVector, const T &key) {
  return lower_bound(sortedVector.begin(), sortedVector.end(), key);
}
template <typename T>
inline typename vector<T>::const_iterator lessThan(
    const std::vector<T> &sortedVector, const T &key) {
  typename vector<T>::const_iterator it =
      lower_bound(sortedVector.begin(), sortedVector.end(), key);
  return it == sortedVector.begin() ? sortedVector.end() : --it;
}
template <typename T>
inline typename vector<T>::const_iterator lessThanEq(
    const std::vector<T> &sortedVector, const T &key) {
  typename vector<T>::const_iterator it =
      upper_bound(sortedVector.begin(), sortedVector.end(), key);
  return it == sortedVector.begin() ? sortedVector.end() : --it;
}

// set helper
// test by iterator_macro_test.cpp
template <typename T>
inline typename set<T>::const_iterator moreThan(const set<T> &container,
                                                const T &key) {
  return container.upper_bound(key);
}
template <typename T>
inline typename set<T>::const_iterator moreThanEq(const set<T> &container,
                                                  const T &key) {
  return container.lower_bound(key);
}
template <typename T>
inline typename set<T>::const_iterator lessThan(const set<T> &container,
                                                const T &key) {
  typename set<T>::const_iterator it = container.lower_bound(key);
  return it == container.begin() ? container.end() : --it;
}
template <typename T>
inline typename set<T>::const_iterator lessThanEq(const set<T> &container,
                                                  const T &key) {
  typename set<T>::const_iterator it = container.upper_bound(key);
  return it == container.begin() ? container.end() : --it;
}

// multiset helper
template <typename T>
inline typename multiset<T>::const_iterator moreThan(
    const multiset<T> &container, T key) {
  return container.upper_bound(key);
}
template <typename T>
inline typename multiset<T>::const_iterator moreThanEq(
    const multiset<T> &container, T key) {
  return container.lower_bound(key);
}
template <typename T>
inline typename multiset<T>::const_iterator lessThan(
    const multiset<T> &container, T key) {
  typename set<T>::const_iterator it = container.lower_bound(key);
  return it == container.begin() ? container.end() : --it;
}
template <typename T>
inline typename multiset<T>::const_iterator lessThanEq(
    const multiset<T> &container, T key) {
  typename set<T>::const_iterator it = container.upper_bound(key);
  return it == container.begin() ? container.end() : --it;
}

// map helper
// test by iterator_macro_test.cpp
template <typename Key, typename Value>
inline typename map<Key, Value>::const_iterator moreThan(
    const map<Key, Value> &container, const Key &key) {
  return container.upper_bound(key);
}
template <typename Key, typename Value>
inline typename map<Key, Value>::const_iterator moreThanEq(
    const map<Key, Value> &container, const Key &key) {
  return container.lower_bound(key);
}
template <typename Key, typename Value>
inline typename map<Key, Value>::const_iterator lessThan(
    const map<Key, Value> &container, const Key &key) {
  typename map<Key, Value>::const_iterator it = container.lower_bound(key);
  return it == container.begin() ? container.end() : --it;
}
template <typename Key, typename Value>
inline typename map<Key, Value>::const_iterator lessThanEq(
    const map<Key, Value> &container, const Key &key) {
  typename map<Key, Value>::const_iterator it = container.upper_bound(key);
  return it == container.begin() ? container.end() : --it;
}

// https://qiita.com/ganyariya/items/df35d253726269bda436
//
// Usage: unordered_map<pair<int, int>, int, HashPair> mp;
struct HashPair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);

    size_t seed = 0;
    seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    return seed;
  }
};

// debug macro
// https://www.creativ.xyz/dump-cpp-652/
//
// test by dump_macro_test.cpp
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (unsigned int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}";
  return os;
}
// deque
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "{";
  for (unsigned int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// unordered_map
template <typename T, typename U>
ostream &operator<<(ostream &os, unordered_map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) { os << *itr << ", "; }
  os << "}";
  return os;
}
// unordered_map with HashFunction
template <typename T, typename U, typename F>
ostream &operator<<(ostream &os, unordered_map<T, U, F> &map_var) {
  os << "{";
  repi(itr, map_var) { os << *itr << ", "; }
  os << "}";
  return os;
}
// unordered_set
template <typename T>
ostream &operator<<(ostream &os, unordered_set<T> &set_var) {
  os << "{";
  repi(itr, set_var) { os << *itr << ", "; }
  os << "}";
  return os;
}
// unordered_set with HashFunction
template <typename T, typename F>
ostream &operator<<(ostream &os, unordered_set<T, F> &set_var) {
  os << "{";
  repi(itr, set_var) { os << *itr << ", "; }
  os << "}";
  return os;
}
// dynamic_modint
ostream &operator<<(ostream &os, const modint &modint_value) {
  os << modint_value.val();
  return os;
}
// static_modint
template <int T>
ostream &operator<<(ostream &os, const static_modint<T> &modint_value) {
  os << modint_value.val();
  return os;
}
#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  DUMPOUT << head;
  if (sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)

// vector<vector<T>>
template <typename T>
void dumpVV(const vector<vector<T>> &vec) {
  DUMPOUT << "{" << endl;
  for (int i = 0; i < vec.size(); i++) {
    DUMPOUT << "  " << vec[i] << endl;
  }
  DUMPOUT << "}" << endl;
}

template <class S, S (*op)(S, S), S (*e)()>
void dumpSegtree(const segtree<S, op, e> &segtree, int size) {
  DUMPOUT << "{";
  for (int i = 0; i < size; i++) {
    if (i > 0) {
      DUMPOUT << ", ";
    }
    DUMPOUT << segtree.get(i);
  }
  DUMPOUT << "}" << endl;
}

template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S),
          F (*composition)(F, F), F (*id)()>
void dumpLazySegtree(
    lazy_segtree<S, op, e, F, mapping, composition, id> &lazySegtree,
    int size) {
  DUMPOUT << "{";
  for (int i = 0; i < size; i++) {
    if (i > 0) {
      DUMPOUT << ", ";
    }
    DUMPOUT << lazySegtree.get(i);
  }
  DUMPOUT << "}" << endl;
}

#else
#define DEB if (false)
#define dump(...)
// vector<vector<T>>
template <typename T>
void dumpVV(const vector<vector<T>> &vec) {
  // Do nothing
}

template <class S, S (*op)(S, S), S (*e)()>
void dumpSegtree(const segtree<S, op, e> &segtree, int size) {
  // Do nothing
}

template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S),
          F (*composition)(F, F), F (*id)()>
void dumpLazySegtree(
    lazy_segtree<S, op, e, F, mapping, composition, id> &lazySegtree,
    int size) {
  // Do nothing
}

#endif

class Solver {
 private:
 public:
  Solver() {}

  void solve() {}
};

// n = sa + k
// n - k == sa
// k < a

ll solve(ll n, ll k) {
  set<ll> aSet;
  for (ll i = 1; i * i <= n - k; i++) {
    if ((n - k) % i == 0) {
      aSet.insert(i);
      aSet.insert((n - k) / i);
    }
  }

  ll answer = 0;
  for (ll a : aSet) {
    if (a > k) {
      answer++;
    }
  }
  return answer;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  // Implement here,
  ll n, k;
  cin >> n >> k;
  cout << solve(n, k) << endl;
}
0