您好,欢迎来到欧得旅游网。
搜索
您的当前位置:首页2018年第九届蓝桥杯【C++省赛B组】【第三题:乘积尾零】

2018年第九届蓝桥杯【C++省赛B组】【第三题:乘积尾零】

来源:欧得旅游网
#include<stdio.h> 
#include<iostream> 
#include<algorithm>
using namespace std;
 
int data[] ={5650,42,35,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,99,
1486,5722,3135,1170,4014,5510,5120,729,2880,9019,
2049,698,4582,4346,4427,6,9742,7340,1230,7683,
5693,7015,6887,7381,4172,4341,2909,2027,7355,59,
6701,65,1671,5978,2704,9926,295,3125,3878,6785,
2066,4247,4800,1578,6652,4616,1113,6205,32,2915,
3966,5291,2904,1285,2193,1428,2265,8730,9436,7074,
6,5510,8243,6114,337,4096,8199,7313,3685,211};

struct node{
	int a2 = 0, a5 = 0;
}; 

node count(int num){
	node temp;
	for(int k = 2; k <= num; k++){
		int result = 0;
		while(num%k==0){
			num /= k;
			result++;
		}
		if(k == 2) temp.a2 = result;
		if(k == 5) temp.a5 = result;
	}
	return temp;

}

int main(){
	int a2=0, a5=0;
	for(int i = 0; i < sizeof(data)/sizeof(int); i++){
		a2 += count(data[i]).a2;
		a5 += count(data[i]).a5;
	}
	cout << min(a2, a5) << endl;
	return 0;
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- ovod.cn 版权所有 湘ICP备2023023988号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务