40pts TLE求助(玄关)
查看原帖
40pts TLE求助(玄关)
1023494
rohitsharmaw楼主2023/11/4 17:06

这是记录

放代码

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    long long n,ans;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        bool flag=true;
        if(i<2)  continue;
        else
        {
            for(int j=2;j<=sqrt(i);j++)
            {
                if(i%j==0)  flag=false;
            }
            if(flag)  ans++;
        }
    }
    printf("%lld",ans);
    return 0;
}

主要只改了快读快写、数据类型、开O2。其他就不会了,在#5-10 TLE

求调,玄关

2023/11/4 17:06
加载中...