tanasaradu

Untitled

Oct 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("inversmodular.in");
  4. ofstream fout("inversmodular.out");
  5. int a,n,cpy;
  6. inline int FI()
  7. {
  8. int d,fi;
  9. d=2;
  10. fi=n;
  11. while(n>1 && d*d<=n)
  12. {
  13. if(n%d==0)
  14. {
  15. fi=(fi/d)*(d-1);
  16. while(!(n%d))
  17. n/=d;
  18. }
  19. d++;
  20. }
  21. if(n>1)
  22. fi=(fi/n)*(n-1);
  23. return fi;
  24. }
  25. inline int LGPUT(int x,int a)
  26. {
  27. int s=1;
  28. while(a)
  29. {
  30. if(a%2)
  31. s=1LL*s*x%cpy;
  32. a/=2;
  33. x=1LL*x*x%cpy;
  34. }
  35. return s;
  36. }
  37. int main()
  38. {
  39. fin>>a>>n;
  40. int x;
  41. cpy=n;
  42. x=FI();
  43. fout<<LGPUT(a,x-1)<<"\n";
  44. fin.close();
  45. fout.close();
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment