modulo c++
#include <bits/stdc++.h>
using namespace std;
int main() {
int MOD = 1e9+7; //MOD = 1000000007
int a = 1224839897; //let a be a large number
int b = 1343589784; //also b is a large number
//then if we perform multiplication, addition or subtraction
//between these integers then they might result to overflow
//to overcome this situation we use modulo with a prime number > 1billion
//alright lets perform those operations...
//MULTIPLICATION
int mul = (a*b) % MOD;
//ADDITION AND SUBTRACTION IS QUITE A TRICKY OPERATION WITH MODULO
//which goes like this...
int add = (a % MOD + b % MOD) % MOD;
int sub = (a % MOD - b % MOD + MOD) % MOD;
cout << "Multiplication : " << mul << '\n';
cout << "Addition : " << add << '\n';
cout << "Subtraction : " << sub << '\n';
//In this way overflow can be handled in many cases.
return 0;
}
//Output...
Multiplication : 312325592
Addition : 568429667
Subtraction : 881250120