给出 q q q 个数,要求每个数 a a a 找到一个正整数 b b b 满足小于 a a a 使得 gcd ( a ⊕ b , a & b ) \gcd(a ~\oplus~b,a~\&~b) gcd(a ⊕ b,a & b) 最大
分类讨论:
- 当 a a a 不是 2 k − 1 2^k-1 2k−1 时,这时我们发现我们只要让 a & b = 0 a~\&~b=0 a & b=0, a ⊕ b = 2 k − 1 a~\oplus~b=2^k-1 a ⊕ b=2k−1就可以了
- 否则,通过打表,发现当 a a a 为质数时,答案为 1 1 1,否则答案为 a a a 的最大因子
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(s) freopen(s".in", "r", stdin), freopen(s."out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
int n, x, i ;
signed main(){
scanf("%d", &n) ;
while (n--) {
scanf("%d", &x) ;
if (!(x & (x + 1))) {
for (i = 2; i * i <= x; i++) if (x % i == 0) break ;
if (i * i > x) puts("1") ;
else printf("%d\n", x / i) ;
} else {
for (i = 1; i < x; i = i << 1 | 1) ;
printf("%d\n", i) ;
}
}
return 0 ;
}
/*
写代码时请注意:
1.ll?数组大小,边界?数据范围?
2.精度?
3.特判?
4.至少做一些
思考提醒:
1.最大值最小->二分?
2.可以贪心么?不行dp可以么
3.可以优化么
4.维护区间用什么数据结构?
5.统计方案是用dp?模了么?
6.逆向思维?
*/