fork(2) download
  1. // Name:- Kunal Sheth
  2.  
  3. // Problem:- The Rise and Fall of Power
  4.  
  5. // Link:- http://w...content-available-to-author-only...f.com/problems/MARCHA4
  6.  
  7. // Site:- CodeChef
  8.  
  9.  
  10.  
  11. //header files
  12.  
  13. #include<iostream>
  14. #include<cstdio>
  15. #include<algorithm>
  16. #include<vector>
  17. #include<map>
  18. #include<cmath>
  19. #include<cstring>
  20. using namespace std;
  21.  
  22. //end of header files
  23.  
  24.  
  25. //definitions
  26.  
  27. #define MOD 1000000007
  28. #define llu long long unsigned
  29. #define lld long long
  30. #define ld long
  31. #define BSIZE 20
  32.  
  33. //end of definitions
  34.  
  35.  
  36. //fast input
  37.  
  38. int scan_d() {int ip=getchar_unlocked(),ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked());for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return ret;}
  39. long scan_ld() {long ip=getc(stdin),ret=0;for(;ip<'0'||ip>'9';ip=getc(stdin));for(;ip>='0'&&ip<='9';ip=getc(stdin))ret=ret*10+ip-'0';return ret;}
  40. long long scan_lld() {long long ip=getc(stdin),ret=0;for(;ip<'0'||ip>'9';ip=getc(stdin));for(;ip>='0'&&ip<='9';ip=getc(stdin))ret=ret*10+ip-'0';return ret;}
  41. long long unsigned scan_llu() {long long unsigned ip=getc(stdin),ret=0;for(;ip<'0'||ip>'9';ip=getc(stdin));for(;ip>='0'&&ip<='9';ip=getc(stdin))ret=ret*10+ip-'0';return ret;}
  42.  
  43. //end of fast input
  44.  
  45.  
  46. //extra functions
  47.  
  48. long long first(int n,int k)
  49. {
  50. long double nlogn=n*log10(n);
  51. long double first=pow(10,nlogn-floor(nlogn)+k-1);
  52. return (long long)(first);
  53. }
  54.  
  55. long long e_b_sq(int bs,int po,int mod)
  56. {
  57. if(po==0)
  58. return 1;
  59. if(po==1)
  60. return bs;
  61. if(po&1)
  62. {
  63. long long ans=e_b_sq(bs,po/2,mod);
  64. return (((ans*ans)%mod)*bs)%mod;
  65. }
  66. long long ans=e_b_sq(bs,po/2,mod);
  67. return (ans*ans)%mod;
  68. }
  69.  
  70. //end of extra fnctions
  71.  
  72.  
  73. //main
  74.  
  75. int p[]={
  76. 1,
  77. 10,
  78. 100,
  79. 1000,
  80. 10000,
  81. 100000,
  82. 1000000,
  83. 10000000,
  84. 100000000,
  85. 1000000000
  86. };
  87. char ch[][10]={
  88. {'\0'},
  89. {'0','\0'},
  90. {'0','0','\0'},
  91. {'0','0','0','\0'},
  92. {'0','0','0','0','\0'},
  93. {'0','0','0','0','0','\0'},
  94. {'0','0','0','0','0','0','\0'},
  95. {'0','0','0','0','0','0','0','\0'},
  96. {'0','0','0','0','0','0','0','0','\0'}
  97. };
  98. int main()
  99. {
  100. int t;
  101. t=scan_d();
  102. while(t--)
  103. {
  104. int n=scan_d();
  105. int k=scan_d();
  106. long long l=e_b_sq(n,n,p[k]);
  107. long long temp=l,len=0;
  108. do
  109. {
  110. len++;
  111. temp/=10;
  112. }while(temp);
  113. printf("%lld %lld%s\n",first(n,k),l,ch[k-len]);
  114. }
  115. return 0;
  116. }
Runtime error #stdin #stdout 0s 4060KB
stdin
Standard input is empty
stdout
Standard output is empty