fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,b) for(int i=a;i<b;i++)
  4. #define ll unsigned long long
  5. class ThreeDigits{
  6. public: bool checkzero=false;
  7. public:
  8. ll power(ll x,ll y,ll mod){
  9. if(y<=0) return 1;
  10. ll z=power(x,y/2,mod);
  11. if(y%2){
  12. if((z*z)>= mod || (z*z*x)>=mod) checkzero=true;
  13. return (((z*z)%mod)*x)%mod;
  14. }
  15. else {
  16. if((z*z)>= mod) checkzero=true;
  17. return (z*z)%mod;
  18. }
  19. }
  20. public:
  21. string calculate(int X, int Y, int Z) {
  22. checkzero=false;
  23. ll n1=X,y=Y,z=Z;
  24. ll res=power(n1,y,z*1000LL);
  25. long double ans=(res*1.0)/z;
  26. string x=to_string(ans);
  27. int idx=1;
  28. rep(i,0,x.length()) if(x[i]=='.') {idx=i;break;}
  29. string final_ans="";
  30. if(checkzero) rep(i,0,3-idx) final_ans+="0";
  31. rep(i,0,idx+4) final_ans+=x[i];
  32. // cout<<final_ans<<endl;
  33. return final_ans;
  34. }
  35. void print(){
  36. cout<<calculate(3,5,7)<<endl;
  37. cout<<calculate(4,7,32)<<endl;
  38. cout<<calculate(3,2,36)<<endl;
  39. cout<<calculate(7,4,47)<<endl;
  40. cout<<calculate(13,6,479)<<endl;
  41. cout<<calculate(1234,56789,123456)<<endl;
  42. cout<<calculate(999999999,128,1000000)<<endl;
  43. }
  44. };
  45. int main(){
  46. //freopen("input.txt", "r", stdin); // redirects standard input
  47. //freopen("output1.txt", "w", stdout); // redirects standard output
  48. ThreeDigits obj;
  49. obj.print();
  50. //int t;
  51. //cin>>t;
  52. //while(t--){
  53. // int x,y,z;
  54. // cin>>x>>y>>z;
  55. // cout<<obj.calculate(x,y,z)<<endl;
  56. //}
  57. }
  58.  
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
34.714
512.000
0.250
51.085
076.845
133.942
000.000