1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
/*Je ne pourrais être tenu pour responsable des dommages irrémédiables que pourrait provoquer ce code*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int getMaxPower(int n)
{
return(log(n)/log(2));
}
int modulo(int n, int modulo_n)
{
int currentPower = getMaxPower(n) - getMaxPower(modulo_n);
int temp = n;
while(currentPower>=0)
{
int currentModulo = modulo_n<<currentPower;
while(temp>=currentModulo)
{
temp -= currentModulo;
}
currentPower--;
}
return temp;
}
int main(void)
{
int i;
fprintf(stderr, "%d\n", modulo(1000,7));
return EXIT_SUCCESS;
} |
Partager