zawatins-library

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

View the Project on GitHub zawa-tin/zawatins-library

:heavy_check_mark: Divisor(約数列挙)
(src/math/Divisor.hpp)

概要

std::vector<long long> divisor(long long x)

試し割りを用いた素朴な約数列挙

機能

計算量

Verified with

Code

#pragma once

#include <vector>
#include <algorithm>

namespace zawa {

    std::vector<long long> divisor(long long x) {
        std::vector<long long> res;

        for (long long i = 1 ; i * i <= x ; i++) {
            if (x % i) continue;
            res.emplace_back(i);
            if (i * i != x) res.emplace_back(x / i);
        }
        std::sort(res.begin(), res.end());

        return res;
    }

}// namespace zawa
#line 2 "src/math/Divisor.hpp"

#include <vector>
#include <algorithm>

namespace zawa {

    std::vector<long long> divisor(long long x) {
        std::vector<long long> res;

        for (long long i = 1 ; i * i <= x ; i++) {
            if (x % i) continue;
            res.emplace_back(i);
            if (i * i != x) res.emplace_back(x / i);
        }
        std::sort(res.begin(), res.end());

        return res;
    }

}// namespace zawa
Back to top page