Advertisement
a53

erm9

a53
Jun 20th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. string baza,exp;
  5. unsigned long long b,e,cor=0,n,mod=9,nr=1,p;
  6. unsigned long long Mod1()
  7. {
  8. unsigned long long R=0;
  9. for (int i=0; i<exp.size(); ++i)
  10. R=(10*R%6+exp[i]-48)%6;
  11. return R;
  12. }
  13. unsigned long long Mod2()
  14. {
  15. unsigned long long R=0;
  16. for (int i=0; i<baza.size(); ++i)
  17. R=(10*R%mod+baza[i]-48)%mod;
  18. return R;
  19. }
  20. int main ()
  21. {
  22. cin>>baza;
  23. cin>>exp;
  24. n=Mod2();
  25. if(n==3||n==6||n==9)
  26. {
  27. if(exp.size()==1&&exp[0]=='1') cout<<n<<"\n";
  28. else cout<<"9\n";
  29. return 0;
  30. }
  31. p=Mod1();
  32. while(p)
  33. {
  34. if(p%2==1)
  35. {
  36. nr=(nr*n)%mod;
  37. p--;
  38. }
  39. else
  40. {
  41. n=(n*n)%mod;
  42. p/=2;
  43. }
  44. }
  45. if(nr) cout<<nr<<"\n";
  46. else cout<<"9\n";
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement