1138 – Trailing Zeroes (III)

Problem Link

#Solution

#include<bits/stdc++.h>
using namespace std;
int co,m;
int zero(int n)
{
int q=5;
co=0;
int t=q;
while(n/t)         //while(n)
{                              //{

co+=n/t;      //{n/=5;
t*=q;        //co+=n;
}
return co;
}
int bs(int start,int end)
{
int mid=(start+end)>>1;
if(start>end)
return -1;

if(zero(mid)==m)
{
while(zero(mid)==m)
mid–;
return mid+1;

}

if(zero(mid)<m)
return bs(mid+1,end);
else if(zero(mid)>m)
return bs(start,mid-1);
}
int main()
{
int t,cs=1;
cin>>t;
while(t–)
{cin>>m;
int ans=bs(1,1e9);
printf(“Case %d: “,cs++);
if(ans==-1)
puts(“impossible”);
else
cout<<ans<<endl;
}

}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s