
solution
找末尾0的个数,即找有多少对2和5
==>问题等价于寻找所给数据中,有多少个2和5的因子,较少出现的因子次数即为0的个数
#include <iostream>
using namespace std;
int main()
{
// 请在此输入您的代码
printf("31");
return 0;
}
#include<stdio.h>
#include<math.h>
typedef long long ll;
int main(){
ll x, two = 0, five = 0, ans = 0;
for(int i = 0; i < 100; i++){
scanf("%lld", &x);
while(x % 2 == 0){
two++;
x /= 2;
}
while(x % 5 == 0){
five++;
x /= 5;
}
}
if(two > five) two = five;
printf("%lld", two);
return 0;
}
这篇文章介绍了如何使用C++编写程序,通过计算数据中2和5的因子数量来确定一个整数序列末尾0的个数,主要展示了使用while循环遍历并计数因子的方法。
真题C 语言 A 组-乘积尾零&spm=1001.2101.3001.5002&articleId=137027741&d=1&t=3&u=840a1997111d4956804b254a5fd73996)
3416

被折叠的 条评论
为什么被折叠?



