只是想问一下这两种代码为什么一个100tps一个90tps
查看原帖
只是想问一下这两种代码为什么一个100tps一个90tps
1092947
Ssim_on_wxs楼主2023/10/29 14:50

rt

AC 100

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	for(int i = 2;i <= sqrt(n);i ++){
		if(n % i == 0){cout<<n / i<<endl;break;}
	}
	return 0;
} 

90 一个TLE

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	for(int i = sqrt(n) + 1;i <= n;i ++){
		if(n % i == 0){cout<<i<<endl;break;}
	}
	return 0;
} 

感觉枚举次数基本差不多,为什么有区别啊

2023/10/29 14:50
加载中...