zl程序教程

您现在的位置是:首页 >  Java

当前栏目

因数的多少——解题报告

2023-02-18 16:26:26 时间

因子数

【1,n】中的数进行余数的判断,若为0,则是它的一个因数,对应的优化便是【1,sqrt(n)】的判断

1,返回因子数

返回因子数 题目的意思是:一个数只含有2,3,5,7因子,返回它包含的因子数

#include<cstdio>
#define ll long long
int main() {
	ll n;
	int yueshu[4] = { 2,3,5,7 }; 
	while (scanf("%lld", &n) != EOF && n != 0) {       //输入的判定
		ll ans = 1;                          //结果
		for (int i = 0; i < 4; ++i) {
			int count = 0;
			for (; n % yueshu[i] == 0; n /= yueshu[i])
			    count++; //判断约数的个数
			ans *= count + 1;                               //公式
		}

		printf("%lld\n", ans);
	}
	return 0;
}
```![请添加图片描述](https://img-blog.csdnimg.cn/8f8af94e276d4805b4e6be3fe8b29fa1.png)