Created
July 17, 2019 12:57
-
-
Save ivary43/d21c7479a36e5fd0272928e4d91affb9 to your computer and use it in GitHub Desktop.
Large number mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to compute num (mod a) | |
int mod(string num, int a) | |
{ | |
// Initialize result | |
int res = 0; | |
// One by one process all digits of 'num' | |
for (int i = 0; i < num.length(); i++) | |
res = (res*10 + (int)num[i] - '0') %a; | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment