A ninth Cup Blue Bridge Group third question: Zero Tail product

Title: zero tail product
10 rows below, each line has 10 integers, you find at the end of their product is the number zero?
5650 4542 35544739464114 38719073904329
2,758,794,961,135,659 5,245,743,230,514,434 6704 3594
9937 1173 6,866,339,747,597,557 3,070,228,714,539,899
1,486,572,231,351,170 4014 5,510,512,072,928,809,019
2,049,698,458,243,464,427 6,469,742,734,012,307,683
5693 7015 6,887,738,141,724,341 2,909,202,773,555,649
6,701,664,516,715,978 2,704,992,629,531,253,878 6785
2066 4247 4,800,157,866,524,616 1,113,620,532,642,915
3,966,529,129,041,285 2,193,142,822,658,730 9436 7074
689 5510 8243 6114 337 4,096,819,973,133,685,211

Question: when multiplying numbers ending in what will be 0? (Figures 2 and 5 when multiplied together will be 0) 5 i.e., a 2 and a product of a number 0 appears. Given two numbers a, b.

If a, b can be split into a = 2 * 5 * c, b = 2 * 5 * d like this form (wherein a, b 2 and 5 in number unknown), then the number of statistical product mantissa 0, statistics is multiplied by the number of how many of the 2 and 5. (Take 2 and 5 that the least number of occurrences)

. 1 #include <bits / STDC ++ H.>
 2  the using  namespace STD;
 . 3  
. 4  int main ()
 . 5  {
 . 6      int n-, SUM1 = 0 , SUM2 = 0 ;
 . 7      for ( int I = 0 ; I < 100 ; I ++ ) {
 . 8          CIN >> n;
 . 9          // Analyzing integer n is the number of digits 2 
10          the while (n% 2 == 0 ) {
 . 11              SUM1 ++ ;
 12 is              n = n / 2 ;
13          }
 14          // determines how many integer numbers n. 5 
15          the while (% n . 5 == 0 ) {
 16              SUM2 ++ ;
 . 17              n = n / . 5 ;
 18 is          }
 . 19      }
 20 is      int ANS = min (SUM1, SUM2);
 21 is      COUT ANS << << endl;   
 22 is      return  0 ;
 23 is }

 

 

 

 

Guess you like

Origin www.cnblogs.com/mld-code-life/p/11825270.html