fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. long long pot_szybkie(long long a, unsigned int n)
  6. {
  7. if(n==0)
  8. return 1;
  9.  
  10. if(n%2 == 1) //gdy n jest nieparzyste
  11. return a * pot_szybkie(a, n - 1);
  12.  
  13. //żeby dwa razy nie wchodzić w tą samą rekurencję
  14. long long w = pot_szybkie(a, n/2);
  15. return w * w;
  16. }
  17.  
  18. int main() {
  19. cout << (int)abs(pot_szybkie(3, 100)) % 10000 << endl;
  20. cout << (int)pow(3, 100) % 10000;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
-3648
3647