Advertisement
Farjana_akter

Untitled

Nov 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long int check(long long int mid)
  5. {
  6. long long int cnt=0,n=mid;
  7. for(int j=5; n/j>=1; j*=5)
  8. {
  9. cnt+=(n/j);
  10. }
  11. return cnt;
  12.  
  13. }
  14.  
  15. int main()
  16. {
  17. long long int test,cas,q,i,j,high,low,mid;
  18. cin>>test;
  19. for(cas=1; cas<=test; cas++)
  20. {
  21. long long int a,res=0,flag=0;
  22. cin>>q;
  23. cout<<"Case "<<cas<<": ";
  24. if(q==1)
  25. {
  26. cout<<5<<endl;
  27. continue;
  28. }
  29. high=5*q,low=0,res=0;
  30. while(low<=high)
  31. {
  32. mid=(high+low)/2;
  33. // cout<<"Mid "<<mid<<endl;
  34. a=check(mid);
  35. // cout<<"zero cnt "<<a<<endl;
  36. // cout<<"q "<<q<<endl;
  37. if(a==q)
  38. {
  39. flag=1;
  40. res=mid;
  41. }
  42. if(a>=q)
  43. high=mid-1;
  44. else
  45. low=mid+1;
  46. }
  47. if(flag==1)
  48. cout<<res<<endl;
  49. else
  50. cout<<"impossible"<<endl;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement