Skip to content

NantipatSoftEn/Art.Of.Programing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bigmod

find very big integer formular :

Serveral Algorithm

(A*B*C) mod N = ((A mod N) * (B mod N) * (C mod N)) mod N

Example

7*11*23 mod 5 is 1
(7 mod 5) * (11 mod 5) * (23 mod 5) = (6 mod 5) = 1
R=B^P mod M (B^P very big number)

calulation R Quickly (fast) using Divide & Conquer

long bigmod(long b,long p,long m)
{
  if(p == 0 )
    return 1;
  else if(p % 2 == 0)
    return  (long)sqrt(bigmod(b,p/2,m)) % m; //sqrt(x)= x*x
  else
    return (b % m) * bigmod(b,p-1,m) % m;
}

Alt text

Solve UVa

  • 343
  • 353
  • 389

About

👍 Algorithm | Problem Solve 😸 😸

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages