Skip to content

Instantly share code, notes, and snippets.

@josejuan
Created July 1, 2012 22:45
Show Gist options
  • Save josejuan/3029921 to your computer and use it in GitHub Desktop.
Save josejuan/3029921 to your computer and use it in GitHub Desktop.
reduccion
int mod4(int n) {
return n % 4;
}
int div4(int n) {
return n / 4;
}
int divX(int n, int x) {
return n / x;
}
int divX4(int n) {
return divX(n, 4);
}
int sumDiv5(int n) {
int d, s = 0;
for(d = 1; d <= 5; d++)
s += divX(n, d);
return s;
}
int distributiva(int N, int P) {
// 1 * P + 2 * P + ... + (N-1) * P + N * P = P * N * (N+1) / 2
int i, S = 0;
for(i = 1; i <= N; i++)
S += i * P;
return S;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment