fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long a,n;
  5.  
  6. unsigned long long luythua(long x, long p)
  7. {
  8. if (p == 0) return 1;
  9. if (p == 1) return x;
  10.  
  11. if (p%2==0) return (luythua(x,p/2)*luythua(x,p/2))%10;
  12. return (luythua(x,p/2)*luythua(x,p/2)*x)%10;
  13. }
  14.  
  15. void cstc()
  16. {
  17. cin >> a >> n;
  18. cout << luythua(a, n);
  19. }
  20.  
  21. int main()
  22. {
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0); cout.tie(0);
  25. // freopen("CSTC.INP","r",stdin);
  26. // freopen("CSTC.OUT","w",stdout);
  27.  
  28. cstc();
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
2 2003
stdout
8