20200910 day5 刷题记录

1 1019 陶陶学数学

题意

给定\(n\),找出具有\(n\)个正因子的最小的正整数\(m\).
\(n=4\)\(m=6\),因为6有4个不同正整数因子:1,2,3,6;且是最小的有4个因子的整数。

题解

因为题意中\(m\leq 50000\),所以我们考虑一下枚举,如果纯暴力是\(n^2\),显然不可以,我们可以观察发现,我们只要在验证\(m\)是否成立的时候,只需要判断到\(\sqrt{m}\)即可,在\(\sqrt{m}\)内,成立一个,意味着根号后还有一个,边界特判一下即可。这样复杂度是\(O(m\sqrt{m})\),显然是可以接受的。

未AC原因

为啥不想枚举呢... 费那个劲...

代码


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	for (int i = 1;i <= 50000;i++){
	int xz = sqrt(i),tot = 0;
	if (xz * xz == i)
	{
		tot = 1;
		xz--;
	}
	for (int j = 1;j <= xz;j++)
	{
		if (i % j == 0) tot += 2;
	}
	if (tot == n){
		printf("%d\n",i);
		return 0;
	}
		}
} 
posted @ 2020-09-10 08:44  刘子闻  阅读(79)  评论(0)    收藏  举报