Advertisement
Saleh127

Light OJ 1282 / logarithm

Oct 26th, 2021
1,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. /***
  2.  created: 2021-10-26-23.02.54
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define nl '\n'
  10.  
  11. ll bigmod(ll a,ll c,ll d)
  12. {
  13.     if(c==0) return 1LL;
  14.     ll x=bigmod(a,c/2,d);
  15.     x=(x*x)%d;
  16.     if(c%2==1LL)
  17.     {
  18.         x=(x*a)%d;
  19.     }
  20.     return x;
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26.  
  27.     test
  28.     {
  29.          ll n,m,i,j,k,last,first;
  30.  
  31.          scanf("%lld %lld",&n,&k);
  32.  
  33.          last=bigmod(n,k,1000);
  34.  
  35.          double y= (double)k*log10(n);
  36.  
  37.          y=y-(ll)y;
  38.  
  39.          double ans= pow(10,y);
  40.  
  41.          first = ans*100;
  42.  
  43.          /// if want first x digit then first = ans*pow(10,x-1);
  44.  
  45.          printf("Case %d: %03lld %03lld\n",cs,first,last);
  46.     }
  47.  
  48.  
  49.    return 0;
  50. }
  51.  
  52. /**
  53. X=n^k;
  54. X can be expressed as a powwer of 10;
  55. K * log10(N) = log10(10^y)
  56. => K * log10(N) = y * log10(10)
  57. => y = K * log10(N)
  58. Now y will be a decimal number of form abc—.xyz—
  59. Therefore,
  60. NK = 10^(abc—.xyz—)
  61. NK = 10abc— + 0.xyz—
  62. NK = 10abc— * 100.xyz—
  63. **/
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement