.........MLE好开心
查看原帖
.........MLE好开心
1612650
Aya_ylxatch楼主2025/2/7 22:11
#include<iostream>
#include<deque>
using namespace std;
int n,T;
deque<int>first,second;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}while('0'<=c&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
void firstpos(int x){
	first.clear();
	int y=x;
	while(x%2==0)x/=2;
	if(x==1)return;
	for(int i=3;i*i<=x;i+=2){
		if(x%i==0){
			int f=y/i;
			for(int j=f-i/2;j<=f+i/2;++j){
				first.push_back(j);
			}return;
		}
	}int f=y/x;
	for(int j=f-x/2;j<=f+x/2;++j){
		first.push_back(j);
	}
}
void secondpos(int x){
	second.clear();
	if(x&1&&x!=1){
		second.push_back(x/2);
		second.push_back(x/2+1);
	}else{
		int cnt=0;
		while(x%2==0){
			cnt++;
			x/=2;
		}
		if(x==1)return;
		second.push_back(x/2);
		second.push_back(x/2+1);
		for(int i=1;i<=cnt;++i){
			second.push_front(second.front()-1);
			second.push_back(second.back()+1);
		}
	}
}
int main(){
	//freopen("create.in","r",stdin);
	T=read();
	while(T--){
		n=read();
		if(n<=0){
			puts("IMPOSSIBLE");
			continue;
		}
		firstpos(n);
		secondpos(n);
		bool k1=1,k2=1;
		if(first.front()<0||first.empty())k1=0;
		if(second.front()<0||second.empty())k2=0;
		if(!k1&&!k2)puts("IMPOSSIBLE");
		else if(!k1&&k2){
			printf("%d = ",n);
			if(second.front()==0){
				second.pop_front();
				printf("%d",second.front());
				second.pop_front();
			}else{
				printf("%d",second.front());
				second.pop_front();
			}for(const auto&v:second)printf(" + %d",v);
			puts("");
		}else if(k1&&!k2){
			printf("%d = ",n);
			if(first.front()==0){
				first.pop_front();
				printf("%d",first.front());
				first.pop_front();
			}else{
				printf("%d",first.front());
				first.pop_front();
			}for(const auto&v:first)printf(" + %d",v);
			puts("");
		}else if(k1&&k2){
			printf("%d = ",n);
			if(first.front()>second.front()){
				if(first.front()==0){
					first.pop_front();
					printf("%d",first.front());
					first.pop_front();
				}
				else{
					printf("%d",first.front());
					first.pop_front();
				}for(const auto&v:first)printf(" + %d",v);
				puts("");
			}
			else{
				if(second.front()==0){
					second.pop_front();
					printf("%d",second.front());
					second.pop_front();
				}else{
					printf("%d",second.front());
					second.pop_front();
				}for(const auto&v:second)printf(" + %d",v);
				puts("");
			}
		}
	}
	return 0;
}
2025/2/7 22:11
加载中...