#include using namespace std; int main() { //子命题: // 找到大于n的第一个m的倍数。 // 也可以理解为 整数除法向上取整 int n = 107; int m = 5; //方法1:数学公式法,这个现在看来理解别人代码时有用,否则看不懂别人在干什么。 //证明: //https://blog.csdn.net/qq_41661919/article/details/95733619 int res = ((n - 1) / m + 1) * m; cout << res << endl; //方法2:借助于C++自带的上取整函数,这个操作太妙了,好理解,我要是想使用上取整,就这个了。 res = ceil((long double) n / m) * m; cout << res << endl; return 0; }