唯一分解定理E - Trailing Zeroes (III)

唯一分解定理E - Trailing Zeroes (III)

唯一分解定理E - Trailing Zeroes (III)

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include
#include<string.h>
#include
#define ll long long
#define hengheng main ()
using namespace std;
const int maxx=1e6+10;
int suanling(int n)
{
int geshu=0;
while(n)
{
geshu+=n/5;
n/=5;
}
return geshu;
}

ll judge(ll n)
{
ll xiao=5,da=1e9;
ll mid;
ll ans=0;
while(xiao<=da)
{
mid=(xiao+da)/2;
if(suanling(mid)==n)
{
ans=mid;// ok
da=mid-1;
}
else if(suanling(mid)>n)
da=mid-1;
else
xiao=mid+1;
}
return ans;
}

int hengheng
{
ll t,n;ll i;
int ans;
cin>>t;
int count=1;
while(t–)
{
int mid;
cin>>n;
ans=0;
ll zhegeshu=n;

	 if(judge(n)==0)
	 {
	 	printf("Case %d: impossible\n",count);
	 	count++;
	 }
	 
	 else
	 {
	 	 printf("Case %d: %d\n",count,judge(n));
	 	 count++;
	 }
}

return 0;

}