0

I have a problem with modulo sharing, I don't know why the parameters given are incorrect

Error C2660: inverse_modulo does not take 2 arguments C++

Error C2660: mod does not take 2 arguments C++

int inverse_modulo(int a, int p, int is, int ij)
{
    a = mod(is - ij, p);
    //a = a % p;
    for (int x = 1; x < p; x++)
        if ((a * x) %p == 1)
            return x;
}

int mod(int is, int ij, int p) {
    long  x = 1, y = ij;
    while (ij > 0) {
        if (ij % 2 == 1) {
            x = (x * y) % p; 
        }
        y = (y * y) % p; 
        ij /= 2;
    }
    return x % p;
}


int getSecret(std::vector<int> ids, std::vector<int> ms, int p) {
    start = clock();
    auto sum = 0;
    auto i = 0;
    for (auto is : ids) {
        auto prod = ms[i];
        for (auto ij : ids) {
            if (is == ij)
                continue;
            prod *= mod(is, -ij, p);
            prod *= inverse_modulo(mod(is - ij, p), p);
        }
        sum += prod;
        i++;
    }
    auto M = mod(sum, p);
    return M;
}```
Kubazooo
  • 115
  • 1
  • 6

1 Answers1

0

Your int mod function takes 3 arguments:

  1. int is
  2. int ij
  3. int p

You are, however, calling it with less than that (i.e. the very first line in inverse_modulo body):

a = mod(is - ij, p);

Arguments should be separated by a ',' (comma). Therefore you are calling it with only two arguments:

  1. is - ij - note that you can pass a whole expression as one argument
  2. p

If you would like to pass is, ij and p as arguments, you would call your mod function like so:

a = mod(is, ij, p);

Similarly, your inverse_modulo is called with less arguments than needed:

prod *= inverse_modulo(mod(is - ij, p), p);
  1. mod(is - ij, p) - which is a mistake in itself
  2. p
PajLe
  • 791
  • 1
  • 7
  • 21