Lanqiao Cup Product Tail Zero

C++ version:

For each number, calculate how many 2 products and how many 5 products can be decomposed, and then accumulate them, and finally output the smaller value of the number of 2 and the number of 5, because only 2*5 will appear 0 .

int c1=0,c2=0;
	
	for(int i=1;i<=10;i++)
		for(int j=1;j<=10;j++)
		{
			int x;
			int t=x;
			cin>>x;
			while(x%2==0)
			{
				c1++;
				x=x/2;
			}
			while(t%5==0)
			{
				c2++;
				t=t/5;
			}
		}
	
	cout<<min(c1,c2);

Python version:

Of course violent calculation

if __name__ == '__main__':
    with open("in.txt", "r") as f:
        ans = 1
        for line in f:
            list = line.split()
            for i in list:
                ans = ans * int(i)
        print(ans)
if __name__ == '__main__':
    ans = 1
    for i in range(0, 10):
        n = int(input())
        ans *= n
    print(ans)

 

Guess you like

Origin blog.csdn.net/qq_44115065/article/details/109031360