2018.4.21 T1数学题

数学题
【问题描述】
令 A,B,C 为三个质数(A≤ B ≤ C),P =A · B · C。
给出 P,求 B。
【输入格式】
从文件 math.in 中读入数据。
一行一个正整数 P。
【输出格式】
输出到文件 math.out 中。
一行一个正整数 B。
【样例输入】
30
【样例输出】
3
【数据规模】
对于 20% 的数据,P ≤ 10 3 ;
对于 40% 的数据,P ≤ 10 6 ;
对于 60% 的数据,P ≤ 10 9 ;
对于 80% 的数据,P ≤ 10 12 ;

对于 100% 的数据,10 ≤ P ≤ 10 14 。

-----------------------------------------------------------------

这次据说是对面大佬们的入学考试

P 大的吓人,但并没有什么用

可以发现 A <= P开立方, 然后 B 就 <= sqrt(P/A)

我 sqrt(P) 枚举直接过

#include <cstdio>
#include <cmath>
using namespace std;
#define LL long long
const int Ma=1e7+7;
LL n;
LL pri[700000];
int vis[Ma<<1];
int cnt,nu;
void pre(LL x) {
	pri[++cnt]=2;
	for (LL i=3;i<=x;i+=2) {
		if (!vis[i]) {
			pri[++cnt]=i;
			for (LL k=i;k<=x;k+=i)
				vis[k]=1;
			}
		}
}
int main() {
	freopen("math.in","r",stdin);
	freopen("math.out","w",stdout);
	scanf("%lld",&n);
	pre(ceil(sqrt(n)));
	for (int i=1;i<=cnt;i++) {
		while (n%pri[i]==0) {//有 7*7*7
		nu++,n/=pri[i];
		if (nu==2) {
			printf("%lld",pri[i]);
			return 0;
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41893580/article/details/80033418
今日推荐