全红,but样例是对的。
查看原帖
全红,but样例是对的。
1390387
vector_STL_楼主2024/11/23 23:26
#include<iostream>
using namespace std;
#define int long long
const int N=1e8;
int f[N],s[N];
int check(int a,int b){
	if(a!=b){
		return s[b]-s[a-1];
	}
	
}
signed main(){
	for(int i=0;i<N;i++){
		ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	}
	
	int a;
	cin>>a;
	for(int i=1;i<=a;i++){
		f[i]=i;
		s[i]=s[i-1]+f[i];
	}
	for(int i=1;i<=a;i++){
		int l=1,r=a,ans=0;
		while(l<=r){
			int mid=l+r>>1;
			if(check(i,mid)==a){
				cout<<min(i,mid)<<" "<<max(i,mid)<<endl;
				break;
			}
			else if(check(i,mid)>a){
				r=mid-1;
			}
			else{
				l=mid+1;
			}
		}
	}
}
2024/11/23 23:26
加载中...