Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define ll long long
- ll binPow(ll base, ll exp)
- {
- if(exp == 0) ///Un número elevado a la cero es 1
- return 1;
- if(exp == 1)
- return base;
- ll pot = binPow(base, exp/2);
- return pot*pot * binPow(base, exp%2);
- }
- ll binModPow(ll base, ll exp, ll mod)
- {
- if(exp == 0) ///Un número elevado a la cero es 1
- return 1;
- if(exp == 1)
- return base%mod;
- ll pot = binPow(base, exp/2)%mod;
- return ( ((pot*pot)%mod) * (binPow(base, exp%2)%mod) )%mod;
- }
- int main()
- {
- for(int i=0; i<60; i++)
- {
- ///Muestra potencias de 2
- cout << binPow(2, i) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment