Codeforces Round #671 (Div. 2)


Codeforces Round #671 (Div. 2)

Codeforces Round #671 (Div. 2)

A

int main(){
	int t=read();
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int e1=0,o1=0,e2=0,o2=0;
		int focus=0;
		if(s.size()%2==1){
			focus=1;
		}
		else focus=2;
		for(int i=s.size()-1,t=n;i>=0;i--,t--){
			int type=0;
			if((s[i]-'0')%2==0){
				type=2;
			}
			else type=1;
			if(type==1){
				if(t%2==1) o1++;
				else o2++;
			}
			else{
				if(t%2==1) e1++;
				else e2++;
			}
		}
		if(focus==1){
			if(o1>0){
				cout<<"1\n";
			}
			else{
				cout<<"2\n";
			}
		}
		else{
			if(e2>0){
				cout<<"2\n";
			}
			else{
				cout<<"1\n";
			}
		}
	}
	return 0;
}

B

int main(){
	int t=read();
	while(t--){
		ll k=read();
		int cnt=0;
		ll now=0;
		ll p=1;
		while(k>=now*2+p*p){
			k-=now*2+p*p;
			now=now*2+p*p;
			p*=2;
			cnt++;
		//	cout<

C

int vn[1001];
int main(){
	int t=read();
	while(t--){
		int n=read(),q=read();
		int ans=0,cnt=0;
		bool ch=true;
		for(int i=1;i<=n;++i){
			vn[i]=read();
			int diff=vn[i]-q;
			if(diff!=0)ch=false,cnt++;
			ans+=diff;
		}	
		if(ch==true){
			 cout<<'0'<<'\n';
		}
		else if(ans==0||cnt

D

int main(){
	int n=read();
	vectornp(n);
	for(int i=0;i());
	vectorans;
	vectorps;
	int pt1=0,pt2=ceil(n/2.0);
	for(int i=0;i=ans.back()){
					ps.push_back(np[pt2++]);
				}
				if(pt2=0&&i+1

E

vectorans;
vectorprimelist;
vectorprimecnt;
int main(){
	int t=read();
	while(t--){
		ans.clear();
		primecnt.clear();
		primelist.clear();
		int n=read();
		bool isp=true;
		for(ll i=2;i*i<=n;++i){
			if(n%i==0){
				isp=false;
				primelist.push_back(i);
				primecnt.push_back(1);
				n/=i;
				while(n%i==0){
					n/=i;
					++primecnt.back();
				}
			}
		}
		if(isp==true){
			cout<pre;
		pre.push_back(1);
		for(int i=0;iist;
			int now=1;
			for(int j=1;j<=primecnt[i];++j){
				now*=primelist[i];
				for(int k=0;k=0;--u)
				ans.push_back(ist[u]); 
			else{
				if(ist.size()!=2)
				ans.push_back(ist.back()); 
				for(int u=ist.size()-2;u>=0;--u)
				if(u!=1)ans.push_back(ist[u]);
				if(ist.size()>1)
				ans.push_back(ist[1]);
			}
			for(int u:ist)
			pre.push_back(u);
		}
		for(int i=0;i