Inverse over a range

Правка en1, от rahul_1234, 2017-07-03 11:16:36

If I want 1/i for 1<=i<=5000000, i.e. inv[i]

inv[1] = 1;
for (int i=2; i<p; ++i)
	inv[i] = (p - (p/i) * inv[p%i] % p) % p;

I used this but it times out. So I wanted a way for this.

Besides that, if I use fact[i-1]*invfact[i] : would that solve? It is not giving me correct answer so plz tell me what is wrong over here?

Теги inverse

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский rahul_1234 2017-07-03 11:16:36 370 Initial revision (published)