问题标题: 酷町堂:3717 急!!!

0
0
已解决
范浩轩
范浩轩
资深守护
资深守护

题目链接: 酷町堂:3717

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
bool cmp(int x,int y)
{
    return x>y;
}
bool isprime(int x){
    if(x==1) return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0) return false;
    }
    return true;
}
int ys(int n)
{
    int cnt=0,a;
    if(n==1)
    {
        return 1;
    }
    for(int i=n;i>=n/2;i--)
    {
        if(n%i==0)
        {
            cnt++;
            a=i;
        }
        if(cnt==2)
        {
            return i;
        }
    }
    return a;
}
int main()
{
    long long n;
    cin>>n;
    if(isprime(n)==true)
    {
        cout<<"YES";
    }
    else{
        cout<<ys(n);
    }
    return 0;
}

Time Limit Exceeded:50分


0
已采纳
赵近其
赵近其
中级天翼
中级天翼

数字太大,超时了!!

我要回答