Files
python/TangDou/LuoGuBook/P3601_Prepare_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
710 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
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;
}