holiday/8.16/S-TrailingZeroes/main.cpp

63 lines
842 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include<cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
int q,n;
int t1=0,t;
// int i=0;
//n*5!n*5的阶乘
int find5(int n)//WA 以为/5一次就可以把前面*5的个数找出来
{
int res=0;
while(n/5>0)
{
n/=5;
res+=n;
}
return res;
}
int erfen(int l,int r)//TLE 没用二分超时
{
// ++i;
if(l>=r)
{
return l;
}
int mid=l+r;
mid/=2;
int now=mid+find5(mid);
if(now==q)
{
return mid;
}
if(now<q)return erfen(mid+1,r);
else return erfen(l,mid-1);
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&q);
// q=t1+1;
n=erfen(q-find5(q),q);
// while(n+n/5<q)
// {
// ++i;
// n++;
// }
// printf("%d:%d->%d ",i,q-q/5,n);
if(n+find5(n)==q)//WA 这里忘改了
{
printf("Case %d: %d\n",++t1,n*5);
}
else
{
printf("Case %d: impossible\n",++t1);
}
}
return 0;
}