

Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!


#include <bits/stdc++.h> #define ll long long using namespace std; ll Bin(ll val){ bool digit[64]; int nDigit=0; while (val >0){ digit[nDigit++]=(val % 2 == 1)?true:false; val = val >> 1; } cout << "Numero cifre: "<<nDigit<<" valore in binario: "; for (int i=nDigit-1; i>=0;i--) cout << digit[i]; cout << endl; } ll modular_pow(ll base, ll exponent, int modulus) { ll result = 1; while (exponent > 0) { if (exponent % 2 == 1){ result = (result * base) % modulus; cout << "(result * base)% mod = " << result <<endl; } exponent = exponent >> 1; base = (base * base) % modulus; cout << "(base * base)% mod = " << base<<endl; } return result; } /*
res = 1; for (int i=0; i<e; i++) res = (res * b) % mod; cout<<"Chk= "<< res <<endl; system("pause"); return 0; }