差分+找规律

http://codeforces.com/contest/1110/problem/C

C. Meaningless Operations

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.

Suppose you are given a positive integer aa. You want to choose some integer bb from 11 to a−1a−1 inclusive in such a way that the greatest common divisor (GCD) of integers a⊕ba⊕b and a&ba&b is as large as possible. In other words, you'd like to compute the following function:

 

f(a)=max0<b<agcd(a⊕b,a&b).f(a)=max0<b<agcd(a⊕b,a&b).

Here ⊕⊕ denotes the bitwise XOR operation, and && denotes the bitwise AND operation.

The greatest common divisor of two integers xx and yy is the largest integer gg such that both xx and yy are divided by gg without remainder.

You are given qq integers a1,a2,…,aqa1,a2,…,aq. For each of these integers compute the largest possible value of the greatest common divisor (when bb is chosen optimally).

Input

The first line contains an integer qq (1≤q≤1031≤q≤103) — the number of integers you need to compute the answer for.

After that qq integers are given, one per line: a1,a2,…,aqa1,a2,…,aq (2≤ai≤225−12≤ai≤225−1) — the integers you need to compute the answer for.

Output

For each integer, print the answer in the same order as the integers are given in input.

Example

input

Copy

3
2
3
5

output

Copy

3
1
7

Note

For the first integer the optimal choice is b=1b=1, then a⊕b=3a⊕b=3, a&b=0a&b=0, and the greatest common divisor of 33 and 00 is 33.

For the second integer one optimal choice is b=2b=2, then a⊕b=1a⊕b=1, a&b=2a&b=2, and the greatest common divisor of 11 and 22 is 11.

For the third integer the optimal choice is b=2b=2, then a⊕b=7a⊕b=7, a&b=0a&b=0, and the greatest common divisor of 77 and 00 is 77.

对于C[i-1] C[i]  C[i+1],令a=C[i+1]-C[i],b=C[i]-C[i-1],则一次操作是将a,b的位置换了一下,自己可以试试。 

步骤:

  1. 判断第一个和最后一个元素必相等
  2. c[i]-[i-1]排序后和t[i]-t[i-1]排序后一定相等
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define res register int 
const int maxn=1e5+10;
int a[maxn],b[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
		scanf("%d",&b[i]);
	if(a[0]==b[0]&&a[n-1]==b[n-1]){
		for(int i=0;i<n-1;i++){
			a[i]=a[i+1]-a[i];
			b[i]=b[i+1]-b[i];
		}	
		sort(a,a+n-1);
		sort(b,b+n-1);
		int i;
		for(i=0;i<n-1;i++)
			if(a[i]!=b[i]) break;
		if(i==n-1) printf("Yes");
		else printf("No"); 
	}else{
		printf("No");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值