| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
暴搜,1,1的情况也考虑了,怎么会wrong?请大牛们看看(附代码)#include <iostream>
#include <math.h>
using namespace std;
bool isprime(int n)
{
int i;
if (n == 1)
{
return false;
}
if (n == 2)
{
return true;
}
if (n != 1 && n != 2)
{
for (i = 2; i <= (int) sqrt((double) n); i++)
{
if (n % i == 0)
{
return false;
}
}
}
return true;
}
int main()
{
int n, num, res = 1, i, j;
int max = -1;
cin>>n;
for (i = 0; i < n; i++)
{
cin >> num;
if(n == 1)
{
cout<<num<<endl;
return 0;
}
for (j = num / 2; j >= 2; j--)
{
if (num % j == 0)
{
if (isprime(j))
{
if (max < j)
{
max = j;
res = num;
}
break;
}
}
}
}
cout << res << endl;
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator