fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #define ll unsigned long long
  4. using namespace std;
  5.  
  6. long long int fastpowmod(long long int b, long long int p, long long int m)
  7. {
  8. if(p == 0 || b == 1) return (1 % m);
  9.  
  10. if(p % 2)
  11. return (b*fastpowmod(b,p-1,m)) % m;
  12.  
  13. long long int c = fastpowmod(b,p/2,m);
  14. return (c*c) % m;
  15. }
  16. ll power(ll x, int y)
  17. {
  18. ll temp;
  19. if( y == 0)
  20. return 1;
  21. temp = power(x, y/2);
  22. if (y%2 == 0)
  23. return temp*temp;
  24. else
  25. {
  26. if(y > 0)
  27. return x*temp*temp;
  28. else
  29. return (temp*temp)/x;
  30. }
  31. }
  32.  
  33. int main() {
  34. std::ios::sync_with_stdio(false);
  35. int T;
  36. cin>>T;
  37. ll n,k,a,answer;
  38. double originalNumber,fractional;
  39. while(T-->0)
  40. {
  41. cin>>n>>k;
  42. double originalNumber = n*log10(n);
  43. a = originalNumber; //Typecasting the decimal value to integer to get the part before fractional
  44. fractional = originalNumber-a; //To get the decimal part i.e x.something
  45. answer=pow(10,(fractional))*power(10,k-1);
  46. cout<<answer<<" ";
  47. ll answer2=fastpowmod(n,n,power(10,k));
  48. ll digits=(log10(answer2)+1);
  49. if(answer2==0)
  50. if(n==10)
  51. for(ll i=0;i<k-1;i++)
  52. cout<<0;
  53. else
  54. for(ll i=0;i<k;i++)
  55. cout<<0;
  56. if(n==10)
  57. if(digits!=k)
  58. {
  59. cout<<0;
  60. digits++;
  61. }
  62. if(digits==k)
  63. cout<<answer2;
  64. cout<<endl;
  65. }
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0s 3280KB
stdin
1
9 9
stdout
387420488 387420489