fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define vll vector<long long>
  5. #define MAXK 1000000
  6. #define mapll map<long long,long long>
  7. ll a,b,c;
  8. ll binpow(ll a, ll n, ll c){
  9. ll res = 1;
  10. a %= c;
  11. while(n != 0){
  12. //Neu bit cuoi cung cua n la bit 1
  13. if(n % 2 == 1){
  14. res *= (a % c);
  15. res %= c;
  16. }
  17. //Dich phai 1 bit
  18. n /= 2;
  19. //Nhan a voi a
  20. a *= (a % c);
  21. a %= c;
  22. }
  23. return res;
  24. }
  25. int main(){
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28. cout.tie(nullptr);
  29. freopen("LASTDG.inp","r",stdin);
  30. freopen("LASTDG.out","w",stdout);
  31. cin>>a>>b>>c;
  32. ll vl;
  33. ll k=a%10;
  34. if(k==1||k==5||k==0||k==6){
  35. cout<<k;
  36. return 0;
  37. }else if(k==4||k==9){
  38. vl=2;
  39.  
  40. }else{
  41. vl=4;
  42. }
  43. ll tmp=binpow(b,c,vl);
  44. ll ans=a%10;
  45. for(ll i=2;i<=tmp;i++){
  46. ans=ans*(a%10);
  47. ans=ans%10;
  48. }
  49. cout<<ans;
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty