P17544题解
P17544 二五一十
这道题首先先把原来的数据中的非有效位数0给去掉。然后再看,同时x2和x5相当于没乘,所以是通过x2或者x5把末尾给转化成0,那么对于末尾是非零偶数的数就x5变成0,对于5则x2变成0。其他的数字乘以这两个数字都不会增加0,因此可以写代码了。
#include <iostream>
#define MAXN 100
using namespace std;
int T;
long long n;
long long ans;
int main()
{
scanf("%d" , &T);
while(T--)
{
ans = 0;
scanf("%ld" , &n);
while(!(n%10)) n/=10;
while(1)
{
if(n%10 == 0) n/=10;
else if((n%10) % 2 == 0) n*=5;
else if((n%10) %5 == 0) n*=2;
else break;
}
while(n)
{
ans++;
n/=10;
}
printf("%d\n" , ans);
}
return 0;
}

浙公网安备 33010602011771号