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;
}

转载于:https://www.cnblogs.com/Staceyacm/p/10781807.html

CodeForces - 1110C-Meaningless Operation(打表找规律)相关推荐

  1. CodeForces - 1339E Perfect Triples(打表找规律)

    题目链接:点击查看 题目大意:序列 s 是一个无限数列,现在给出构造方法: 选择三个数 a b c ,将其依次加到序列 s 的最后面,三个数需要满足: a b c 在序列 s 中均未出现过 a b c ...

  2. [codeforces 1327E] Count The Blocks 打表找规律+根据规律找公式+优化公式

    Educational Codeforces Round 84 (Rated for Div. 2)   比赛人数13522 [codeforces 1327E]  Count The Blocks  ...

  3. CodeForces - Insertion Sort(打表找规律)

    题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...

  4. 点分治问题 ----------- P3727 曼哈顿计划E[点分治+博弈SG函数打表找规律]

    题目链接 解题思路: 1.首先对于每个操作我们实际上是一个博弈问题 对于k=1的操作就是很基础的NIM游戏就是找到一条链的异或和为0 对于k=2的操作通过达打表找规律: 如果s是奇数那么偶数的SG函数 ...

  5. CodeForces - 603C Lieges of Legendre(博弈+找规律)

    题目链接:点击查看 题目大意:首先给出n堆石子和一个k值,两人轮流按照规则操作,不能操作的一方即为失败,每一次都有两种操作: 从任意一堆石子中取走一个石子 任选一堆偶数个的石子,将其转换成k堆x/2的 ...

  6. Yet Another Meme Problem(打表找规律)

    Try guessing the statement from this picture http://tiny.cc/ogyoiz. You are given two integers AA an ...

  7. hdu_5894_hannnnah_j’s Biological Test(打表找规律)

    题目链接:hdu_5894_hannnnah_j's Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...

  8. D. Pythagorean Triples(1487D)(打表找规律 + 二分)

    D. Pythagorean Triples(1487D)(打表找规律 + 二分) 题目来源:D. Pythagorean Triples 题意: 给定一个 n,求满足以下条件的数对 (a, b, c ...

  9. Ural 2045. Richness of words 打表找规律

    2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...

  10. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

最新文章

  1. 使用Python、OpenCV计算轮廓的中心
  2. 解决keepalived脑裂问题
  3. 为什么人人都该懂点LLVM
  4. 小程序webview不全屏_有赞微信商城和有赞微信小程序什么不一样
  5. 解决SVN 每次操作都需要重输入用户名密码问题
  6. python 元组 字典 列表 序列化与反序列化
  7. 一个python程序员需要掌握的知识-Python程序员鲜为人知但你应该知道的17个问题...
  8. oracle 无法解析指定的连接标识符
  9. Linux16.04安装Matlab2016b详细教程
  10. 三星系统和鸿蒙系统,又一设备直升鸿蒙系统,现有操作系统被抛弃,和三星的想法一样!...
  11. 工作404-判断浏览器函数
  12. 【JMeter】Thread Group下的组件Sampler取样器
  13. jquery指定节点设css,jquery 获取和设置节点属性 css样式
  14. 小程序把图片转换成base64
  15. 前后端分离,nginx解决跨域问题
  16. Atitit webservice之道 艾提拉著 目录 1. 基本说明Web Service 1 2. 基本概念与内部构成 2 2.1. Web services要使用两种技术: XML SOAP
  17. 用友文件服务器设置,u8文件服务器如何设置
  18. mac下二进制文件查看
  19. 把你的IDE搬进浏览器里——JetBrains Projector 初体验
  20. 腾讯北大合作的稀疏大模型训练加速方案HET入选国际顶会VLDB

热门文章

  1. SM37作业条目的存储表
  2. 善用Object.defineProperty巧妙找到修改某个变量的准确代码位置
  3. SAP S4CRM和C4C的技术比较
  4. 截屏当前界面_华为手机居然有这3种神奇的截屏方法,用过后,我就再也离不开了...
  5. java ibatis 获取执行的sql_小程序官宣+JAVA 三大框架基础面试题
  6. java机试 数据结构_来看看阿里面试的一面都面了些什么笔试+机试(java岗)
  7. basic和python_PythonBasic
  8. 剑指offer03-数组中重复的数字(java)|leetcode刷题
  9. html5游戏指尖跟随,图片跟随手指滑动
  10. onclick 调用php,AJAX调用PHP简单应用