Saleh127

Lo 1138

Jul 25th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. ll a;
  7. ll nZero(ll x)
  8. {
  9. ll ans=0;
  10. while(x)
  11. {
  12. ans+=(x/5);
  13. x/=5;
  14. }
  15. return ans;
  16. }
  17. void searchh()
  18. {
  19. ll five,mid,lo=0,hi=100000000000,ans=0;
  20. while(lo<=hi)
  21. {
  22. mid=(lo+hi)/2;
  23. five=nZero(mid);
  24. if(five==a)
  25. {
  26. ans=mid;
  27. hi=mid-1;
  28. }
  29. else if(five<a)
  30. {
  31. lo=mid+1;
  32. }
  33. else
  34. {
  35. hi=mid-1;
  36. }
  37. }
  38. if(ans==0) printf("impossible\n");
  39. else printf("%lld\n",ans);
  40. }
  41. int main()
  42. {
  43. fellow_junior
  44.  
  45. ll t,c,d,i,j,k,l;
  46. cin>>t;
  47. for(i=1;i<=t;i++)
  48. {
  49. cin>>a;
  50. printf("Case %lld: ",i);
  51. searchh();
  52. }
  53. return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment