Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long int check(long long int mid)
- {
- long long int cnt=0,n=mid;
- for(int j=5; n/j>=1; j*=5)
- {
- cnt+=(n/j);
- }
- return cnt;
- }
- int main()
- {
- long long int test,cas,q,i,j,high,low,mid;
- cin>>test;
- for(cas=1; cas<=test; cas++)
- {
- long long int a,res=0,flag=0;
- cin>>q;
- cout<<"Case "<<cas<<": ";
- if(q==1)
- {
- cout<<5<<endl;
- continue;
- }
- high=5*q,low=0,res=0;
- while(low<=high)
- {
- mid=(high+low)/2;
- // cout<<"Mid "<<mid<<endl;
- a=check(mid);
- // cout<<"zero cnt "<<a<<endl;
- // cout<<"q "<<q<<endl;
- if(a==q)
- {
- flag=1;
- res=mid;
- }
- if(a>=q)
- high=mid-1;
- else
- low=mid+1;
- }
- if(flag==1)
- cout<<res<<endl;
- else
- cout<<"impossible"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement