Product tail by zero


Title: zero tail product

The following 10 rows, each row having 10 integers, you find at the end of their product is the number zero?

5650 4542 3554 473 946 4114 3871 9073 90 4329 
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594 
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899 
1486 5722 3135 1170 4014 5510 5120 729 2880 9019 
2049 698 4582 4346 4427 646 9742 7340 1230 7683 
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649 
6701 6645 1671 5978 2704 9926 295 3125 3878 6785 
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915 
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074 
689 5510 8243 6114 337 4096 8199 7313 3685 211 

Note: You need to submit is an integer representing the number of zeros at the end. Do not fill out any extra content.

#include<cstdio>
#include<iostream>
using namespace std;
int data[100] ={5650,4542,3554,473,946,4114,3871,9073,90,4329,
2758,7949,6113,5659,5245,7432,3051,4434,6704,3594,
9937,1173,6866,3397,4759,7557,3070,2287,1453,9899,
1486,5722,3135,1170,4014,5510,5120,729,2880,9019,
2049,698,4582,4346,4427,646,9742,7340,1230,7683,
5693,7015,6887,7381,4172,4341,2909,2027,7355,5649,
6701,6645,1671,5978,2704,9926,295,3125,3878,6785,
2066,4247,4800,1578,6652,4616,1113,6205,3264,2915,
3966,5291,2904,1285,2193,1428,2265,8730,9436,7074,
689,5510,8243,6114,337,4096,8199,7313,3685,211};

int main(){
int a5=0,a2=0;
int i;

for(i=0;i<100;i++)
{
	while(data[i]%5==0)
    {
		a5++;
		data[i]/=5;
	}
}

for(i=0;i<100;i++)
{
	while(data[i]%2==0)
    {
		a2++;
		data[i]/=2;
	}
}
printf("%d\n",a2<a5?a2:a5);
	return 0;
}

 

Answer: 31

Tip: int a5, a2 = 0; such an approach can results in VC6.0.

 

 

Released seven original articles · won praise 18 · views 9926

Guess you like

Origin blog.csdn.net/qq_40816779/article/details/104080491