为什么不会tle
查看原帖
为什么不会tle
366595
zty_luogu楼主2021/10/6 15:06
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define F(III,MMM,NNN) for(register int III=MMM;III<=NNN;III++)
typedef long long int ll;
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define re register
const int N=1010,
		  mod=10000007;
int main(){
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		if(n%i==0){
			cout<<n/i;
			return 0;
		}
	}
	return 0;
}

按理来说卡得好一点应该能卡到将近10^9的数据吧

还有为什么埃氏筛有时候会mle有时候不会(按理来说不应该要mle都mle吗)

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define F(III,MMM,NNN) for(register int III=MMM;III<=NNN;III++)
typedef long long int ll;
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define re register
const int N=1010,
		  mod=10000007;
bool a[10005]={};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		if(!a[i])
		for(int j=i*2;j<=n;j+=i){
			a[j]=1;
		}
	}
	for(int i=n;i>=2;i--)
	{
		if(!a[i]&&n%i==0){
			cout<<i;
			return 0;
		}
	}
	return 0;
}

2021/10/6 15:06
加载中...