power with mod(int a,int b, int m) in CPP.

Revision en1, by a7n007, 2022-01-20 04:43:38

int pow(int a,int b,int m){ cout<<a<<b<<endl; if(b == 1) return a % m; if(b % 2 == 0){ int t = pow(a,b/2,m); return (1ll * t * t % m); } else{ int t = pow(a,(b-1)/2,m); t = (1ll * t * t % m); return (1ll * a * t % m); } }

JUST Works

Tags power, math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English a7n007 2022-01-20 04:43:38 378 Initial revision (published)