Skip to content

Instantly share code, notes, and snippets.

@ivary43
Created July 17, 2019 12:57
Show Gist options
  • Save ivary43/d21c7479a36e5fd0272928e4d91affb9 to your computer and use it in GitHub Desktop.
Save ivary43/d21c7479a36e5fd0272928e4d91affb9 to your computer and use it in GitHub Desktop.
Large number mod
// 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