document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.     @Author : Joel Fernandez
  3.     @Web    : Codebotic.blogspot.com
  4.     @Fecha  : 29/06/2015
  5.     @Tema   : MCD usando Bigmod para numeros con exponentes
  6.  
  7. */
  8.  
  9. #include<iostream>
  10. #include<cstdlib>
  11.  
  12. using namespace std;
  13.  
  14. int bigmod(int a, int b, int n)
  15. {
  16.     int x;
  17.     if(b==0)
  18.        return 1;
  19.     if(b%2==1)
  20.         return((a%n)*bigmod(a,b-1,n))%n;
  21.     else
  22.     {
  23.         x=bigmod(a,b/2,n);
  24.         return((x%n)*(x%n))%n;
  25.     }
  26.  
  27. }
  28. int mcd(int  a, int b )
  29. {
  30.     if(b==0) return a;
  31.     else mcd(b,a%b);
  32. }
  33. int main()
  34. {
  35.     system("color 0a");
  36.     int a,b,n,c;
  37.  
  38.     cout<<"\\t    ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"<<endl;
  39.     cout<<"\\t    º                                                         º"<<endl;
  40.     cout<<"\\t    º       Algoritmo BigMod para Numeros con Exponente       º"<<endl;
  41.     cout<<"\\t    º                                                         º"<<endl;
  42.     cout<<"\\t    ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  "<<endl;
  43.     cout<<endl<<endl;
  44.     cout<<"\\t Ingrese a:";
  45.     cin>>a;
  46.     cout<<"\\t Ingrese b:";
  47.     cin>>b;
  48.     cout<<"\\t Ingrese n:";
  49.     cin>>n;
  50.  
  51.     c=bigmod(a,b,n);
  52.     cout<<"\\t El modulo de (a^b,n)="<<c<<endl;
  53.     cout<<"\\t El Maximo Comun Divisor de(a^b,n)="<<mcd(n,c)<<endl;
  54.  
  55.     return 0;
  56. }
');