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 11to 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

3
2
3
5

Output

3
1
7

Note

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

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

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

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map> using namespace std; int main()
{
int n;
cin>>n;
long long x;
for(int t=0;t<n;t++)
{
scanf("%lld",&x);
long long sum=1;
if(x==3)
{
printf("1\n");
}
else if(x==7)
{
printf("1\n");
}
else if(x==15)
{
printf("5\n");
}
else if(x==31)
{
printf("1\n");
}
else if(x==63)
{
printf("21\n");
}
else if(x==127)
{
printf("1\n");
}
else if(x==255)
{
printf("85\n");
}
else if(x==511)
{
printf("73\n");
}
else if(x==1023)
{
printf("341\n");
}
else if(x==2047)
{
printf("89\n");
}
else if(x==4095)
{
printf("1365\n");
}
else if(x==8191)
{
printf("1\n");
}
else if(x==16383)
{
printf("5461\n");
}
else if(x==32767)
{
printf("4681\n");
}
else if(x==65535)
{
printf("21845\n");
}
else if(x==131071)
{
printf("1\n");
}
else if(x==262143)
{
printf("87381\n");
}
else if(x==524287)
{
printf("1\n");
}
else if(x==1048575)
{
printf("349525\n");
}
else if(x==2097151)
{
printf("299593\n");
}
else if(x==4194303)
{
printf("1398101\n");
}
else if(x==8388607)
{
printf("178481\n");
}
else if(x==16777215)
{
printf("5592405\n");
}
else if(x==33554431)
{
printf("1082401\n");
}
else
{
for(int t=1;t<=26;t++)
{
sum*=2;
if(sum<=x&&sum*2>x)
{
sum*=2;
break;
}
}
cout<<sum-1<<endl;
}
} return 0;
}

CodeForces - 1110C-Meaningless Operation(打表找规律)的更多相关文章

  1. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  2. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  3. Codeforces 193E - Fibonacci Number(打表找规律+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...

  4. codeforces#1090 D. New Year and the Permutation Concatenation(打表找规律)

    题意:给出一个n,生成n的所有全排列,将他们按顺序前后拼接在一起组成一个新的序列,问有多少个长度为n的连续的子序列和为(n+1)*n/2 题解:由于只有一个输入,第一感觉就是打表找规律,虽然表打出来了 ...

  5. Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Beta Round #24 D. Broken robot (打表找规律)

    题目链接: 点击我打开链接 题目大意: 给你 \(n,j\),再给出 \(m[0]\) 的坐标和\(a[0]-a[n-1]\) 的坐标. 让你输出 \(m[j]\) 的坐标,其中 \(m[i]\) 和 ...

  7. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  8. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  9. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  10. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. SpringCloud02 Eureka知识点、Eureka服务端和客户端的创建、Eureka服务端集群、Eureka客户端向集群的Eureka服务端注册

    1 Eureka知识点 按照功能划分: Eureka由Eureka服务端和Eureka客户端组成 按照角色划分: Eureka由Eureka Server.Service Provider.Servi ...

  2. 62-U型数字

    https://nanti.jisuanke.com/t/20683 #include <iostream> using namespace std; int main(){ int ct ...

  3. NOIP2018 解题笔记

    D1T1 铺设道路 在场上并没有想到积木大赛这道原题. 差分之后可以把在$[l, r]$这段区间$ - 1$变成在$l$处$ - 1$,在$r + 1$处$ + 1$,然后最终目标是使$\forall ...

  4. Python3 使用selenium库登陆知乎并保存cookie为本地文件

    Python3 使用selenium库登陆知乎并保存cookie为本地文件 学习使用selenium库模拟登陆知乎,并将cookie保存为本地文件,然后供以后(requests模块)使用,用selen ...

  5. Smarty3——变量修饰器

    变量修饰器可以用于变量, 自定义函数或者字符串. 使用修饰器,需要在变量的后面加上|(竖线)并且跟着修饰器名称. 修饰器可能还会有附加的参数以便达到效果. 参数会跟着修饰器名称,用:(冒号)分开. 同 ...

  6. SQL修改字段类型

    ALTER TABLE 表名 ALTER COLUMN 列名 新的数据类型[(长度)] NULL或NOT NULL 例:ALTER TABLE 教师 ALTER COLUMN 办公室 CHAR(20) ...

  7. URAL 1133 Fibonacci Sequence(数论)

    题目链接 题意 :给你第 i 项的值fi,第 j 项的值是 fj 让你求第n项的值,这个数列满足斐波那契的性质,每一项的值是前两项的值得和. 思路 :知道了第 i 项第j项,而且还知道了每个数的范围, ...

  8. 编写高质量代码改善C#程序的157个建议——建议32:总是优先考虑泛型

    建议32:总是优先考虑泛型 泛型的优点是多方面的,无论泛型类还是泛型方法都同时具备可重用性.类型安全性和高效率等特性,这是非泛型和非泛型方法无法具备的. 以可重用性为例: class MyList { ...

  9. HDU - 1251 统计难题(trie树)

    Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).  Input输入数据的第一部 ...

  10. 【转】Android Android属性动画深入分析

    转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/17841165 开篇 像设计模式一样,我们也提出一个问题来引出我们的内容. 问 ...