algorithm

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

View the Project on GitHub drken1215/algorithm

:heavy_check_mark: floor_ceil
(Others/floor_ceil.hpp)

概要

a が負の整数である場合にも対応した floor(a, b), ceil(a, b)

問題例

Required by

Verified with

Code

#pragma once
#include <bits/stdc++.h>
using namespace std;

// floor, ceil
template<class T> T floor(T a, T b) {
    if (a % b == 0 || a >= 0) return a / b;
    else return -((-a) / b) - 1;
}
template<class T> T ceil(T x, T y) {
    return floor(x + y - 1, y);
}
#line 2 "Others/floor_ceil.hpp"
#include <bits/stdc++.h>
using namespace std;

// floor, ceil
template<class T> T floor(T a, T b) {
    if (a % b == 0 || a >= 0) return a / b;
    else return -((-a) / b) - 1;
}
template<class T> T ceil(T x, T y) {
    return floor(x + y - 1, y);
}
Back to top page