This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
/**
功能:正数+负数取模
n=3为例
MOD就是一直0,1,2,0,1,2这样的向下走,不会乱了规矩
MOD 0 1 2 0 1 2 0 1 2
@ @ @ @ @ @ @ @ @
a -3 -2 -1 0 1 2 3 4 5
*/
int MOD(int a, int b) {
return (a % b + b) % b; //配合数组下标从0开始合适
}
int main() {
int n = 5;
for (int a = -4; a <= 2; a++) {
cout << "a=" << a << " MOD=" << MOD(a, n) << endl;
}
return 0;
}