63 lines
842 B
C++
63 lines
842 B
C++
|
#include <iostream>
|
|||
|
#include<cstdio>
|
|||
|
#include<algorithm>
|
|||
|
#include <cmath>
|
|||
|
using namespace std;
|
|||
|
int q,n;
|
|||
|
int t1=0,t;
|
|||
|
// int i=0;
|
|||
|
//n*5!<21><>n*5<><35><EFBFBD>Ľ׳<C4BD>
|
|||
|
int find5(int n)//WA <20><>Ϊ/5һ<35>ξͿ<CEBE><CDBF><EFBFBD>ǰ<EFBFBD><C7B0>*5<>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD>
|
|||
|
{
|
|||
|
int res=0;
|
|||
|
while(n/5>0)
|
|||
|
{
|
|||
|
n/=5;
|
|||
|
res+=n;
|
|||
|
}
|
|||
|
return res;
|
|||
|
}
|
|||
|
int erfen(int l,int r)//TLE û<>ö<EFBFBD><C3B6>ֳ<EFBFBD>ʱ
|
|||
|
{
|
|||
|
// ++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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
printf("Case %d: %d\n",++t1,n*5);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
printf("Case %d: impossible\n",++t1);
|
|||
|
}
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|