library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub yuruhi/library

:heavy_check_mark: test/Divisors.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ITP1_3_D"
#include "./../math/Divisors.cpp"
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int d : Divisors(c)) {
		ans += a <= d && d <= b;
	}
	cout << ans << '\n';
}
#line 1 "test/Divisors.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ITP1_3_D"
#line 2 "math/Divisors.cpp"
#include <vector>
#include <cmath>
#include <cassert>

template <class T> std::vector<T> Divisors(T n) {
	assert(0 < n);
	std::vector<T> result;
	T i = 1;
	for (; i * i < n; ++i) {
		if (n % i == 0) result.push_back(i);
	}
	bool flag = i * i == n;
	if (flag) result.push_back(i);
	for (i = (int)result.size() - 1 - flag; i >= 0; --i) {
		result.push_back(n / result[i]);
	}
	return result;
}
template <class T> int DivisorsCount(T n) {
	assert(0 < n);
	int cnt = 0;
	T sq = std::sqrt(n);
	for (T i = 1; i <= sq; ++i) {
		cnt += n % i == 0;
	}
	return cnt * 2 - (sq * sq == n);
}
template <class T> T DivisorsSum(T n) {
	assert(0 < n);
	T i = 1, result = 0;
	for (; i * i < n; ++i) {
		if (n % i == 0) result += i + n / i;
	}
	return result + i * (i * i == n);
}
#line 3 "test/Divisors.test.cpp"
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int d : Divisors(c)) {
		ans += a <= d && d <= b;
	}
	cout << ans << '\n';
}
Back to top page