zoukankan      html  css  js  c++  java
  • 乘积尾0


    标题:乘积尾零

    如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零?

    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

    注意:需要提交的是一个整数,表示末尾零的个数。不要填写任何多余内容。

     //其实就是求所能分成的2和5,然后取俩个数个数最小的

     1 #include <iostream>
     2 #include <vector>
     3 using namespace std;
     4 int count2, count5;
     5 void jiSuan(int n){
     6     
     7     while(n){
     8         bool flag = false;
     9         if(n % 5 == 0){
    10             n /= 5;
    11             flag = true;
    12             count5++;
    13         }
    14         if(n % 2 == 0){
    15             flag = true;
    16             count2++;
    17             n /= 2;
    18         }
    19         if(!flag){
    20             break;
    21         }
    22     }
    23 }
    24 int main(){
    25     int N;
    26     for(int i = 0; i < 100; i++){
    27         int N;
    28         cin >> N;
    29         jiSuan(N);
    30     }
    31     if(count2 < count5){
    32         cout << count2;
    33     }else{
    34         cout << count5;
    35     }
    36     return 0;
    37 }

    答案是31

  • 相关阅读:
    leetcode-344-反转字符串
    leetcode-136-只出现一次的数字
    leetcode-350- 两个数组的交集 II
    leetcode-36-有效的数独
    leetcode-283-移动零
    leetcode-387-字符串中的第一个唯一字符
    leetcode-242-有效的字母异位词
    HDU 2612
    Codeforces 1090B
    Codeforces 1090D
  • 原文地址:https://www.cnblogs.com/AGoodDay/p/10582177.html
Copyright © 2011-2022 走看看