0
点赞
收藏
分享

微信扫一扫

Tyvj P2067(质因数分解)


P2067 - [NOIP2012P1]质因数分解 From ​​luchangzhou​​    Normal (OI)

总时限:10s    内存限制:128MB    代码长度限制:64KB

背景 Background


NOIP2012

描述 Description


已知正整数n 是两个不同的质数的乘积,试求出较大的那个质数。

输入格式 InputFormat


 输入只有一行,包含一个正整数n 。

输出格式 OutputFormat


 输出只有一行,包含一个正整数p ,即较大的那个质数。 

样例输入 SampleInput [​​复制数据​​]



21


样例输出 SampleOutput [​​复制数据​​]



7


数据范围和注释 Hint


【数据范围】 
对于 60% 的数据 6 ≤ n ≤ 1000
对于 100%的数据 6 ≤ n ≤ 2*10^9

来源 Source


NOIP2012



O(√n)


注意要枚举1-√n而不是√n-n,数量级差很多。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
#define MAXN (100000+10)
#define MAXAi (1000000000+10)
int n;
int main()
{
cin>>n;
for (int i=2;i<=n;i++)
if (!(n%i))
{
cout<<n/i<<endl;return 0;
}


}





举报

相关推荐

0 条评论