lmori's Library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub lmorinn/library

:heavy_check_mark: verify/AizuOnlineJudge/math/number-theory/ITP1_3_D.test.cpp

Depends on

Code

#include "../../../../template/template.hpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ITP1_3_D"
#include "../../../../math/number-theory/EnumerateDivisors.hpp"

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int a, b, c;
    in(a, b, c);
    int res = 0;
    for (int d : enumerate_divisors(c)) {
        if (a <= d and d <= b) res++;
    }

    out(res);
}
#line 2 "template/template.hpp"
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const unordered_map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << pair_var.first << " " << pair_var.second;
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

void outf() { cout << '\n'; }
template <class T, class... Ts>
void outf(const T &a, const Ts &...b) {
  cout << fixed << setprecision(14) << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion
#line 2 "verify/AizuOnlineJudge/math/number-theory/ITP1_3_D.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ITP1_3_D"
#line 1 "math/number-theory/PrimalityTest.hpp"
__int128_t mod_pow(__int128_t a, long long n, long long m) {
    __int128_t res = 1;
    a %= m;
    while (n) {
        if (n & 1) res = (res * a) % m;
        a = (a * a) % m;
        n >>= 1;
    }
    return res;
}

constexpr long long MR[] = {2, 7, 61};
constexpr long long MRl[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};

bool Miller_Rabin(long long n) {
    long long s = 0;
    long long d = n - 1;
    while ((d & 1) == 0) {
        s++;
        d >>= 1;
    }
    for (int i = 0; i < 3; i++) {
        if (n <= MR[i]) return true;
        __int128_t x = mod_pow(MR[i], d, n);
        if (x != 1) {
            bool ok = false;
            for (int t = 0; t < s; t++) {
                if (x == n - 1) {
                    ok = true;
                    break;
                }
                x = x * x % n;
            }
            if (!ok) return false;
        }
    }
    return true;
}

bool Miller_Rabinl(long long n) {
    long long s = 0;
    long long d = n - 1;
    while ((d & 1) == 0) {
        s++;
        d >>= 1;
    }
    for (int i = 0; i < 7; i++) {
        if (n <= MRl[i]) return true;
        __int128_t x = mod_pow(MRl[i], d, n);
        if (x != 1) {
            bool ok = false;
            for (int t = 0; t < s; t++) {
                if (x == n - 1) {
                    ok = true;
                    break;
                }
                x = x * x % n;
            }
            if (!ok) return false;
        }
    }
    return true;
}

bool brute_force(long long n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

bool is_prime(long long n) {
    if (n == 2) return true;
    if ((n & 1) == 0 or n < 2) return false;
    if (n < 1000) return brute_force(n);
    if (n < 4759123141LL) {
        return Miller_Rabin(n);
    }
    return Miller_Rabinl(n);
}
#line 2 "math/number-theory/Factorize.hpp"

long long find_prime_factor(long long n) {
  if ((n & 1) == 0) return 2;
  long long m = int64_t(powl(n, 0.125)) + 1;
  for (int i = 1; i < n; i++) {
    long long y = 0;
    long long g = 1;
    long long q = 1;
    long long r = 1;
    long long k = 0;
    long long ys = 0;
    long long x = 0;
    while (g == 1) {
      x = y;
      while (k < 3ll * r / 4) {
        y = (__int128_t(y) * y + i) % n;
        k++;
      }
      while (k < r and g == 1) {
        ys = y;
        for (int j = 0; j < min(m, r - k); j++) {
          y = (__int128_t(y) * y + i) % n;
          q = (__int128_t(q) * abs(x - y)) % n;
        }
        g = gcd(q, n);
        k += m;
      }
      k = r;
      r <<= 1;
    }
    if (g == n) {
      g = 1;
      y = ys;
      while (g == 1) {
        y = (__int128_t(y) * y + i) % n;
        g = gcd(abs(x - y), n);
      }
    }
    if (g == n) continue;
    if (is_prime(g)) return g;
    if (is_prime(n / g)) return n / g;
    return find_prime_factor(g);
  }
  return -1;
}

vector<long long> factorize(long long n, bool set = false) {
  vector<long long> res;
  while (!is_prime(n) and n > 1) {
    long long p = find_prime_factor(n);
    if (set) res.emplace_back(p);
    while (n % p == 0) {
      n /= p;
      if (!set) res.emplace_back(p);
    }
  }
  if (n > 1) {
    res.emplace_back(n);
  }
  sort(res.begin(), res.end());
  return res;
}
#line 2 "math/number-theory/EnumerateDivisors.hpp"

vector<long long> enumerate_divisors(long long n, bool sorted_result = false) {
  vector<long long> res = {1};
  long long before = -1;
  long long mul;
  int siz_before = 1;
  for (const long long p : factorize(n)) {
    mul = (p == before ? mul * p : p);
    int siz = (p == before ? siz_before : int(res.size()));
    for (int i = 0; i < siz; i++) {
      res.emplace_back(res[i] * mul);
    }
    before = p;
    siz_before = siz;
  }
  if (sorted_result) sort(res.begin(), res.end());
  return res;
}
#line 4 "verify/AizuOnlineJudge/math/number-theory/ITP1_3_D.test.cpp"

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int a, b, c;
    in(a, b, c);
    int res = 0;
    for (int d : enumerate_divisors(c)) {
        if (a <= d and d <= b) res++;
    }

    out(res);
}
Back to top page